From d244be3a78d481993777cb329c7a044f6c08c4e0 Mon Sep 17 00:00:00 2001 From: ReluctantPirate Date: Fri, 5 Oct 2018 12:02:49 -0400 Subject: [PATCH 1/5] RPS fully functioning, but not pretty RPS bugs fixed, visuals temporary --- Widgets.ino | 137 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 10 deletions(-) diff --git a/Widgets.ino b/Widgets.ino index b1299c3..c8860b6 100644 --- a/Widgets.ino +++ b/Widgets.ino @@ -1,7 +1,7 @@ ////GENERIC VARIABLES bool inChooser = true; enum widgetModes {COIN, D6, SPINNER, TIMER, RPS}; -byte currentWidget = COIN; +byte currentWidget = TIMER; byte currentVal = 1; enum goSignals {INERT, GOING, RESOLVING, EXEMPT}; byte goSignal = EXEMPT; @@ -21,6 +21,13 @@ byte rpsSignal = 0; Color headsColor; Color tailsColor; +int ticksRemaining; +Timer tickTimer; +Timer tickOffsetTimer; +byte tickFace; +enum timerStates {SETTING, TIMING, COMPLETE}; +byte timerState = SETTING; + void setup() { } @@ -49,8 +56,10 @@ void loop() { spinnerDisplay(7, false); break; case TIMER: + currentVal = 1; break; case RPS: + currentVal = 1; rpsDisplay(currentVal); break; } @@ -92,6 +101,10 @@ void loop() { //set up communication byte sendData = (inChooser << 5) + (goSignal << 3) + (inHiding << 2) + (rpsSignal); setValueSentOnAllFaces(sendData); + + //dump click data + buttonSingleClicked(); + buttonDoubleClicked(); } void osLoop() { @@ -133,7 +146,7 @@ void osLoop() { animTimer.set(100); break; case RPS: - currentVal++; + animFrame++; if (currentVal == 2) { currentVal = 0; } @@ -161,6 +174,7 @@ void nextWidget() { case TIMER: currentWidget = RPS; currentVal = 1; + animFrame = 0; break; case RPS: currentWidget = COIN; @@ -280,7 +294,54 @@ void spinnerLoop() { } void timerLoop() { + switch (timerState) { + case SETTING: + //in here we listen for button clicks to increment currentVal, which represents minutes on the timer + if (buttonSingleClicked()) { + currentVal++; + if (currentVal == 6) { + currentVal = 1; + } + } + + //if double clicked, we move on + if (buttonDoubleClicked()) { + ticksRemaining = currentVal * 60; + tickFace = 1; + tickOffsetTimer.set(500); + timerState = TIMING; + } + break; + case TIMING: + //first check to make sure we haven't been cancelled via double click + if (buttonDoubleClicked()) { + timerState = SETTING; + } + //otherwise we simply count down the remaining ticks + if (tickTimer.isExpired()) { + timerCountdownDisplay(true); + tickFace = nextClockwise(tickFace); + tickTimer.set(1000); + tickOffsetTimer.set(500); + } + if (tickOffsetTimer.isExpired()) { + timerCountdownDisplay(false); + ticksRemaining--; + tickOffsetTimer.set(1000); + } + if (ticksRemaining == 0) { + timerState = COMPLETE; + } + break; + case COMPLETE: + if (buttonSingleClicked()) { //back to SETTING! + timerState = SETTING; + animFrame = 0; + } + break; + } + timerDisplay(); } void rpsLoop() { @@ -301,11 +362,6 @@ void rpsLoop() { } if (inHiding) {//check for double clicks or combat - if (buttonDoubleClicked()) { //toggle hiding mode - inHiding = false; - rpsDisplay(currentVal); - } - //we need to evaluate all neighbors, see if they are in RPS hidden mode byte neighborsIWin = 0; byte neighborsILose = 0; @@ -336,6 +392,13 @@ void rpsLoop() { } else if (neighborsIWin > 0) { rpsCombatDisplay(rpsSignal, 2); } + } else {//so I'm alone + rpsDisplay(4); + } + + if (buttonDoubleClicked()) { //toggle hiding mode + inHiding = false; + rpsDisplay(currentVal); } } } @@ -508,6 +571,62 @@ void timerOSDisplay(byte count) { setColorOnFace(WHITE, 0); } +void timerDisplay() {//only handles SETTING and COMPLETE display, the actual countdown is handled elsewhere + switch (timerState) { + case SETTING: + if (animTimer.isExpired()) { + setColor(dim(spinnerColors[currentVal - 1], 25)); + if (animFrame == 0) { + FOREACH_FACE(f) {//just turn on the faces corresponding to the timer choice + if (f <= currentVal) { + setColorOnFace(dim(spinnerColors[currentVal - 1], 100), f); + } + } + animFrame = 1; + } else if (animFrame == 1) {//nothing here, just setting animFrame + animFrame = 0; + } + animTimer.set(500); + } + setColorOnFace(WHITE, 0); + break; + case COMPLETE: + if (animTimer.isExpired()) { + setColor(dim(RED, 25)); + if (animFrame == 0) { + setColor(RED); + animFrame = 1; + } else if (animFrame == 1) { + animFrame = 0; + } + animTimer.set(50); + } + setColorOnFace(WHITE, 0); + break; + } +} + +void timerCountdownDisplay(bool tickOn) { + //first, set background color + int dimness = 255 - (((ticksRemaining - 1) % 60) * 4); + if (ticksRemaining > 240) { //still in the fifth minute + setColor(dim(BLUE, dimness)); + } else if (ticksRemaining > 180) { //in the fourth minute + setColor(dim(GREEN, dimness)); + } else if (ticksRemaining > 120) { //in the third book + setColor(dim(YELLOW, dimness)); + } else if (ticksRemaining > 60) { //in the second minute + setColor(dim(ORANGE, dimness)); + } else {//in the last minute + setColor(dim(RED, dimness)); + } + + //now, if it's the appropriate time, turn on the tick face + if (tickOn) { + setColorOnFace(WHITE, tickFace); + } +} + void rpsDisplay(byte choice) { setColor(OFF); switch (choice) { @@ -540,16 +659,14 @@ void rpsDisplay(byte choice) { } void rpsCombatDisplay(byte choice, byte outcome) { + setColor(OFF); byte brightness; if (outcome == 0) { brightness = 25; - setColor(OFF); } else if (outcome == 1) { brightness = 150; - setColor(OFF); } else if (outcome == 2) { brightness = 255; - setColor(WHITE); } switch (choice) { From 79c3ee6b58dfca3688bd8ef35f146dc8c126e834 Mon Sep 17 00:00:00 2001 From: ReluctantPirate Date: Fri, 2 Nov 2018 18:57:12 -0400 Subject: [PATCH 2/5] RPS and coin display updated --- Widgets.ino | 163 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 99 insertions(+), 64 deletions(-) diff --git a/Widgets.ino b/Widgets.ino index c8860b6..2db9efd 100644 --- a/Widgets.ino +++ b/Widgets.ino @@ -43,8 +43,8 @@ void loop() { switch (currentWidget) { case COIN: goSignal = INERT; - headsColor = spinnerColors[rand(2)]; - tailsColor = spinnerColors[rand(2) + 3]; + headsColor = spinnerColors[random(2)]; + tailsColor = spinnerColors[random(2) + 3]; coinDisplay(inChooser, 3); break; case D6: @@ -214,20 +214,22 @@ void coinLoop() { //there are two ways to start flipping: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) {//were we clicked? isAnimating = true; - animFrame = 20 + rand(1); + animFrame = 32 + (random(1) * 4); goSignal = GOING; } } if (isAnimating) { if (animTimer.isExpired()) { - coinDisplay(inChooser, currentVal); - if (currentVal == 1) { - currentVal = 2; - } else { - currentVal = 1; + coinDisplay(inChooser, currentVal);//display the animation at frame X + if (animFrame % 4 == 2) {//this is the inversion point of value + if (currentVal == 1) { + currentVal = 2; + } else if (currentVal == 2) { + currentVal = 1; + } } - animFrame --;//check for the end of the animation + animFrame --; animTimer.set(75); }//end of timer loop @@ -250,7 +252,7 @@ void d6Loop() { if (isAnimating) { if (animTimer.isExpired()) { - currentVal = rand(5) + 1; + currentVal = random(5) + 1; d6Display(currentVal, false); animFrame ++; animTimer.set(75); @@ -267,7 +269,7 @@ void spinnerLoop() { //there are two ways to start spinning: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) { isAnimating = true; - spinLength = rand(5) + 36; + spinLength = random(5) + 36; spinInterval = 25; animFrame = 0; goSignal = GOING; @@ -383,6 +385,15 @@ void rpsLoop() { } } + if (animTimer.isExpired()) { + if (animFrame == 0) { + animFrame = 1; + } else { + animFrame = 0; + } + animTimer.set(500); + } + //decide how to display win/loss/tie state if (neighborsIWin + neighborsILose + neighborsITie > 0) {//first, do I have neighbors at all? if (neighborsILose > 0) { @@ -424,31 +435,38 @@ void coinDisplay(bool osMode, byte val) { break; } } else {//not in OS mode - switch (val) { - case 1: - setColorOnFace(headsColor, 0); - setColorOnFace(headsColor, 1); - setColorOnFace(headsColor, 2); - setColorOnFace(dim(tailsColor, 25), 3); - setColorOnFace(dim(tailsColor, 25), 4); - setColorOnFace(dim(tailsColor, 25), 5); - break; - case 2: - setColorOnFace(dim(headsColor, 25), 0); - setColorOnFace(dim(headsColor, 25), 1); - setColorOnFace(dim(headsColor, 25), 2); - setColorOnFace(tailsColor, 3); - setColorOnFace(tailsColor, 4); - setColorOnFace(tailsColor, 5); - break; - case 3: - setColorOnFace(headsColor, 0); - setColorOnFace(headsColor, 1); - setColorOnFace(headsColor, 2); - setColorOnFace(tailsColor, 3); - setColorOnFace(tailsColor, 4); - setColorOnFace(tailsColor, 5); - break; + if (val == 3) { //this is the two face display when you exit chooser + setColorOnFace(headsColor, 0); + setColorOnFace(headsColor, 1); + setColorOnFace(headsColor, 2); + setColorOnFace(tailsColor, 3); + setColorOnFace(tailsColor, 4); + setColorOnFace(tailsColor, 5); + } else {//actual animation + Color currentColor; + if (val == 1) { + currentColor = headsColor; + } else { + currentColor = tailsColor; + } + switch (animFrame % 4) { + case 0: + setColor(currentColor); + break; + case 1: + setColor(currentColor); + setColorOnFace(OFF, 1); + setColorOnFace(OFF, 4); + break; + case 2: + setColor(OFF); + break; + case 3: + setColor(currentColor); + setColorOnFace(OFF, 1); + setColorOnFace(OFF, 4); + break; + } } } } @@ -464,7 +482,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { displayArr[0] = true; } else { - displayArr[rand(5)] = true; + displayArr[random(5)] = true; } displayColor = RED; break; @@ -472,7 +490,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = rand(2); + rotationRandomizer = random(2); } displayArr[rotationRandomizer] = true; displayArr[rotationRandomizer + 3] = true; @@ -482,7 +500,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = rand(1); + rotationRandomizer = random(1); } displayArr[rotationRandomizer] = true; displayArr[rotationRandomizer + 2] = true; @@ -493,7 +511,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = rand(2); + rotationRandomizer = random(2); } displayArr[0] = true; displayArr[1] = true; @@ -515,7 +533,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { displayArr[3] = false; } else { - displayArr[rand(5)] = false; + displayArr[random(5)] = false; } displayColor = BLUE; break; @@ -660,34 +678,51 @@ void rpsDisplay(byte choice) { void rpsCombatDisplay(byte choice, byte outcome) { setColor(OFF); - byte brightness; - if (outcome == 0) { - brightness = 25; - } else if (outcome == 1) { - brightness = 150; - } else if (outcome == 2) { - brightness = 255; - } - + bool layout[6]; + bool rockLayout[6] = {true, true, true, true, false, false}; + bool paperLayout[6] = {false, true, true, false, true, true}; + bool scissorLayout[6] = {true, false, true, false, true, false}; + Color currentColor; + //determine layout and default color switch (choice) { - case ROCK: - setColorOnFace(dim(BLUE, brightness), 0); - setColorOnFace(dim(BLUE, brightness), 1); - setColorOnFace(dim(BLUE, brightness), 2); - setColorOnFace(dim(BLUE, brightness), 3); + case 1: + FOREACH_FACE(f) { + layout[f] = rockLayout[f]; + } + currentColor = BLUE; break; - case PAPER: - setColorOnFace(dim(YELLOW, brightness), 1); - setColorOnFace(dim(YELLOW, brightness), 2); - setColorOnFace(dim(YELLOW, brightness), 4); - setColorOnFace(dim(YELLOW, brightness), 5); + case 2: + FOREACH_FACE(f) { + layout[f] = paperLayout[f]; + } + currentColor = YELLOW; break; - case SCISSOR: - setColorOnFace(dim(RED, brightness), 0); - setColorOnFace(dim(RED, brightness), 2); - setColorOnFace(dim(RED, brightness), 4); + case 3: + FOREACH_FACE(f) { + layout[f] = scissorLayout[f]; + } + currentColor = RED; break; } + + //determine flash color change + if (animFrame = 0) { + switch (outcome) { + case 0://losers flash off + currentColor = OFF; + break; + case 2://winners flash on + currentColor = WHITE; + break; + } + } + + //apply the color + FOREACH_FACE(f) { + if (layout[f]) { + setColorOnFace(currentColor, f); + } + } } void rpsOSDisplay(byte frame) { From 0245e4449168789bbb306052f1e97bcc6e9bfa04 Mon Sep 17 00:00:00 2001 From: ReluctantPirate Date: Fri, 2 Nov 2018 21:08:04 -0400 Subject: [PATCH 3/5] color balance and animation update for real blinks --- Widgets.ino | 69 ++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/Widgets.ino b/Widgets.ino index 2db9efd..a7f251b 100644 --- a/Widgets.ino +++ b/Widgets.ino @@ -147,10 +147,10 @@ void osLoop() { break; case RPS: animFrame++; - if (currentVal == 2) { - currentVal = 0; + if (animFrame > 1) { + animFrame = 0; } - rpsOSDisplay(currentVal); + rpsOSDisplay(animFrame); animTimer.set(600); break; } @@ -214,7 +214,7 @@ void coinLoop() { //there are two ways to start flipping: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) {//were we clicked? isAnimating = true; - animFrame = 32 + (random(1) * 4); + animFrame = 32 + (random(1) * 8); goSignal = GOING; } } @@ -233,7 +233,7 @@ void coinLoop() { animTimer.set(75); }//end of timer loop - if (animFrame == 0) { + if (animFrame == 3) { isAnimating = false; } } @@ -269,7 +269,7 @@ void spinnerLoop() { //there are two ways to start spinning: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) { isAnimating = true; - spinLength = random(5) + 36; + spinLength = random(5) + 24; spinInterval = 25; animFrame = 0; goSignal = GOING; @@ -282,10 +282,10 @@ void spinnerLoop() { spinnerDisplay(currentVal, false); animFrame ++; animTimer.set(spinInterval); - } - if (animFrame > spinLength) { - spinInterval += 2; + if (animFrame > 24) { + spinInterval += 2; + } } if (animFrame == spinLength + 24) { @@ -422,13 +422,13 @@ void coinDisplay(bool osMode, byte val) { if (osMode) {//OS display switch (val) { case 1: - setColor(dim(WHITE, 25)); + setColor(dim(WHITE, 128)); setColorOnFace(WHITE, 0); setColorOnFace(WHITE, 1); setColorOnFace(WHITE, 2); break; case 2: - setColor(dim(WHITE, 100)); + setColor(dim(WHITE, 128)); setColorOnFace(WHITE, 3); setColorOnFace(WHITE, 4); setColorOnFace(WHITE, 5); @@ -550,7 +550,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { displayColor = WHITE; - setColor(dim(WHITE, 25)); + setColor(dim(WHITE, 128)); } FOREACH_FACE(f) { @@ -563,18 +563,22 @@ void d6Display(byte num, bool osMode) { void spinnerDisplay(byte face, bool isFinal) { FOREACH_FACE(f) { - setColorOnFace(dim(spinnerColors[f], 25), f); + byte brightness = 160; + if (isFinal) { + brightness = 100; + } + setColorOnFace(dim(spinnerColors[f], brightness), f); } if (isFinal) { setColorOnFace(spinnerColors[face], face); } else { - setColorOnFace(dim(WHITE, 100), face); + setColorOnFace(WHITE, face); } } void spinnerOSDisplay(byte face) { - setColor(dim(WHITE, 25)); + setColor(dim(WHITE, 128)); setColorOnFace(dim(WHITE, 100), 0); setColorOnFace(dim(WHITE, 100), 2); setColorOnFace(dim(WHITE, 100), 4); @@ -582,9 +586,9 @@ void spinnerOSDisplay(byte face) { } void timerOSDisplay(byte count) { - setColor(dim(WHITE, 25)); + setColor(dim(WHITE, 100)); if (count < 6) { - setColorOnFace(dim(WHITE, 100), count); + setColorOnFace(WHITE, count); } setColorOnFace(WHITE, 0); } @@ -597,7 +601,7 @@ void timerDisplay() {//only handles SETTING and COMPLETE display, the actual cou if (animFrame == 0) { FOREACH_FACE(f) {//just turn on the faces corresponding to the timer choice if (f <= currentVal) { - setColorOnFace(dim(spinnerColors[currentVal - 1], 100), f); + setColorOnFace(dim(spinnerColors[currentVal - 1], 128), f); } } animFrame = 1; @@ -610,7 +614,7 @@ void timerDisplay() {//only handles SETTING and COMPLETE display, the actual cou break; case COMPLETE: if (animTimer.isExpired()) { - setColor(dim(RED, 25)); + setColor(dim(RED, 128)); if (animFrame == 0) { setColor(RED); animFrame = 1; @@ -626,7 +630,7 @@ void timerDisplay() {//only handles SETTING and COMPLETE display, the actual cou void timerCountdownDisplay(bool tickOn) { //first, set background color - int dimness = 255 - (((ticksRemaining - 1) % 60) * 4); + int dimness = 255 - (((ticksRemaining - 1) % 60) * 2); if (ticksRemaining > 240) { //still in the fifth minute setColor(dim(BLUE, dimness)); } else if (ticksRemaining > 180) { //in the fourth minute @@ -666,12 +670,12 @@ void rpsDisplay(byte choice) { setColorOnFace(RED, 4); break; case 4://hiding - setColorOnFace(dim(RED, 25), 0); - setColorOnFace(dim(YELLOW, 25), 1); - setColorOnFace(dim(BLUE, 25), 2); - setColorOnFace(dim(RED, 25), 3); - setColorOnFace(dim(YELLOW, 25), 4); - setColorOnFace(dim(BLUE, 25), 5); + setColorOnFace(dim(RED, 128), 0); + setColorOnFace(dim(YELLOW, 128), 1); + setColorOnFace(dim(BLUE, 128), 2); + setColorOnFace(dim(RED, 128), 3); + setColorOnFace(dim(YELLOW, 128), 4); + setColorOnFace(dim(BLUE, 128), 5); break; } } @@ -706,7 +710,7 @@ void rpsCombatDisplay(byte choice, byte outcome) { } //determine flash color change - if (animFrame = 0) { + if (animFrame == 0) { switch (outcome) { case 0://losers flash off currentColor = OFF; @@ -726,11 +730,12 @@ void rpsCombatDisplay(byte choice, byte outcome) { } void rpsOSDisplay(byte frame) { - byte brightness = frame * 230 + 25; - setColor(dim(WHITE, 25)); - setColorOnFace(dim(WHITE, brightness), 0); - setColorOnFace(dim(WHITE, brightness), 2); - setColorOnFace(dim(WHITE, brightness), 4); + setColor(dim(WHITE, 128)); + if (frame == 0) { + setColorOnFace(WHITE, 0); + setColorOnFace(WHITE, 2); + setColorOnFace(WHITE, 4); + } } /////////////////////////// From e073a5c06acfc0b3268d7d13e49c542fc3beaa4a Mon Sep 17 00:00:00 2001 From: ReluctantPirate Date: Sat, 3 Nov 2018 12:26:55 -0400 Subject: [PATCH 4/5] replaced random with rand to fix issues, adjust spinner timing --- Widgets.ino | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Widgets.ino b/Widgets.ino index a7f251b..f1c808b 100644 --- a/Widgets.ino +++ b/Widgets.ino @@ -1,7 +1,7 @@ ////GENERIC VARIABLES bool inChooser = true; enum widgetModes {COIN, D6, SPINNER, TIMER, RPS}; -byte currentWidget = TIMER; +byte currentWidget = SPINNER; byte currentVal = 1; enum goSignals {INERT, GOING, RESOLVING, EXEMPT}; byte goSignal = EXEMPT; @@ -43,8 +43,8 @@ void loop() { switch (currentWidget) { case COIN: goSignal = INERT; - headsColor = spinnerColors[random(2)]; - tailsColor = spinnerColors[random(2) + 3]; + headsColor = spinnerColors[rand(2)]; + tailsColor = spinnerColors[rand(2) + 3]; coinDisplay(inChooser, 3); break; case D6: @@ -214,7 +214,7 @@ void coinLoop() { //there are two ways to start flipping: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) {//were we clicked? isAnimating = true; - animFrame = 32 + (random(1) * 8); + animFrame = 32 + (rand(1) * 8); goSignal = GOING; } } @@ -252,7 +252,7 @@ void d6Loop() { if (isAnimating) { if (animTimer.isExpired()) { - currentVal = random(5) + 1; + currentVal = rand(5) + 1; d6Display(currentVal, false); animFrame ++; animTimer.set(75); @@ -269,7 +269,7 @@ void spinnerLoop() { //there are two ways to start spinning: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) { isAnimating = true; - spinLength = random(5) + 24; + spinLength = rand(5) + 36; spinInterval = 25; animFrame = 0; goSignal = GOING; @@ -284,7 +284,7 @@ void spinnerLoop() { animTimer.set(spinInterval); if (animFrame > 24) { - spinInterval += 2; + spinInterval += 5; } } @@ -482,7 +482,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { displayArr[0] = true; } else { - displayArr[random(5)] = true; + displayArr[rand(5)] = true; } displayColor = RED; break; @@ -490,7 +490,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = random(2); + rotationRandomizer = rand(2); } displayArr[rotationRandomizer] = true; displayArr[rotationRandomizer + 3] = true; @@ -500,7 +500,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = random(1); + rotationRandomizer = rand(1); } displayArr[rotationRandomizer] = true; displayArr[rotationRandomizer + 2] = true; @@ -511,7 +511,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { rotationRandomizer = 0; } else { - rotationRandomizer = random(2); + rotationRandomizer = rand(2); } displayArr[0] = true; displayArr[1] = true; @@ -533,7 +533,7 @@ void d6Display(byte num, bool osMode) { if (osMode) { displayArr[3] = false; } else { - displayArr[random(5)] = false; + displayArr[rand(5)] = false; } displayColor = BLUE; break; From ef673df773d35d6c23ae9d2cbfeac580d0045fef Mon Sep 17 00:00:00 2001 From: ReluctantPirate Date: Sun, 4 Nov 2018 16:03:47 -0500 Subject: [PATCH 5/5] Displays updated for D6, Timer, and Spinner --- Widgets.ino | 60 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/Widgets.ino b/Widgets.ino index f1c808b..3f053bf 100644 --- a/Widgets.ino +++ b/Widgets.ino @@ -1,7 +1,7 @@ ////GENERIC VARIABLES bool inChooser = true; enum widgetModes {COIN, D6, SPINNER, TIMER, RPS}; -byte currentWidget = SPINNER; +byte currentWidget = TIMER; byte currentVal = 1; enum goSignals {INERT, GOING, RESOLVING, EXEMPT}; byte goSignal = EXEMPT; @@ -246,6 +246,7 @@ void d6Loop() { if (buttonSingleClicked() || goSignal == GOING) {//were we clicked? isAnimating = true; animFrame = 0; + spinInterval = 50; goSignal = GOING; } } @@ -255,11 +256,13 @@ void d6Loop() { currentVal = rand(5) + 1; d6Display(currentVal, false); animFrame ++; - animTimer.set(75); + spinInterval += 10; + animTimer.set(spinInterval); } - if (animFrame == 15) { + if (animFrame == 20) { isAnimating = false; + d6Display(currentVal, false); } } } @@ -269,9 +272,8 @@ void spinnerLoop() { //there are two ways to start spinning: get clicked or be commanded if (buttonSingleClicked() || goSignal == GOING) { isAnimating = true; - spinLength = rand(5) + 36; + spinLength = rand(5) + 42; spinInterval = 25; - animFrame = 0; goSignal = GOING; } } @@ -280,15 +282,15 @@ void spinnerLoop() { if (animTimer.isExpired()) { currentVal = nextClockwise(currentVal); spinnerDisplay(currentVal, false); - animFrame ++; + spinLength--; animTimer.set(spinInterval); - if (animFrame > 24) { - spinInterval += 5; + if (spinLength < 24) { + spinInterval = (spinInterval * 23) / 20; } } - if (animFrame == spinLength + 24) { + if (spinLength == 0) { isAnimating = false; spinnerDisplay(currentVal, true); } @@ -301,6 +303,8 @@ void timerLoop() { //in here we listen for button clicks to increment currentVal, which represents minutes on the timer if (buttonSingleClicked()) { currentVal++; + animFrame = 0; + animTimer.set(0); if (currentVal == 6) { currentVal = 1; } @@ -391,7 +395,7 @@ void rpsLoop() { } else { animFrame = 0; } - animTimer.set(500); + animTimer.set(250); } //decide how to display win/loss/tie state @@ -474,6 +478,7 @@ void coinDisplay(bool osMode, byte val) { void d6Display(byte num, bool osMode) { setColor(OFF); Color displayColor; + byte displayBrightness = 255; byte rotationRandomizer = 0; bool displayArr[6] = {false, false, false, false, false, false}; @@ -553,9 +558,14 @@ void d6Display(byte num, bool osMode) { setColor(dim(WHITE, 128)); } + //set brightness + if (isAnimating) { + displayBrightness = 128; + } + FOREACH_FACE(f) { if (displayArr[f] == true) { - setColorOnFace(displayColor, f); + setColorOnFace(dim(displayColor, displayBrightness), f); } } } @@ -597,20 +607,28 @@ void timerDisplay() {//only handles SETTING and COMPLETE display, the actual cou switch (timerState) { case SETTING: if (animTimer.isExpired()) { - setColor(dim(spinnerColors[currentVal - 1], 25)); - if (animFrame == 0) { - FOREACH_FACE(f) {//just turn on the faces corresponding to the timer choice - if (f <= currentVal) { - setColorOnFace(dim(spinnerColors[currentVal - 1], 128), f); + //so we need to tick on the lights every second + setColor(OFF); + if (animFrame < currentVal) {//we are not ready to reset + FOREACH_FACE(f) { + if (f <= animFrame) { + setColorOnFace(spinnerColors[currentVal - 1], f + 1); } } - animFrame = 1; - } else if (animFrame == 1) {//nothing here, just setting animFrame + } + + animFrame++; + + if (animFrame > currentVal) { + animTimer.set(500); animFrame = 0; + } else if (animFrame == currentVal) { + animTimer.set(500); + } else { + animTimer.set(100); } - animTimer.set(500); + setColorOnFace(WHITE, 0); } - setColorOnFace(WHITE, 0); break; case COMPLETE: if (animTimer.isExpired()) { @@ -630,7 +648,7 @@ void timerDisplay() {//only handles SETTING and COMPLETE display, the actual cou void timerCountdownDisplay(bool tickOn) { //first, set background color - int dimness = 255 - (((ticksRemaining - 1) % 60) * 2); + int dimness = 255 - (((60 - (ticksRemaining - 1) % 60)) * 3); if (ticksRemaining > 240) { //still in the fifth minute setColor(dim(BLUE, dimness)); } else if (ticksRemaining > 180) { //in the fourth minute