Created
May 6, 2020 18:27
-
-
Save peow2373/edeb098ab52ab30428b90183d9f54a7b to your computer and use it in GitHub Desktop.
The game "Simon" recreated with a strip of neopixels, where six different buttons are associated with a different color. The strip will display a certain order of colors, and the corresponding buttons must be pressed in the same order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int GREENledPin = 9; // Green LED pin | |
const int REDledPin = 10; // Red LED pin | |
const int BLUEledPin = 11; // Blue LED pin | |
const int GREEN_Button = 8; // the green button | |
const int RED_Button = 2; // the red button | |
const int BLUE_Button = 3; // the blue button | |
const int VIOLET_Button = 4; // the violet button | |
const int ORANGE_Button = 5; // the orange button | |
const int YELLOW_Button = 6; // the yellow button | |
const int MASTER_Button = 7; // the on/off button that activates the game | |
int color = 0; | |
int whichColor0 = 0; | |
int whichColor1 = 0; | |
int whichColor2 = 0; | |
int whichColor3 = 0; | |
int whichColor4 = 0; | |
int whichColor5 = 0; | |
int colors[] = {0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 10, 200, 240, 10, 255, 180, 10, 25, 255, 255, 255}; | |
// Green // Red // Blue // Violet // Orange // Yellow // Black | |
int unsigned long delayStart = 0; // time the delay starts | |
bool delayRunning = true; // true if still waiting for delay to finish | |
int gameState = 0; | |
int rounds[] = {0,0,0,0,0,0}; | |
bool colorState = true; | |
bool timeState = true; | |
bool firstButton; | |
bool secondButton; | |
bool thirdButton; | |
bool fourthButton; | |
bool fifthButton; | |
bool sixthButton; | |
int testColor0 = 0; | |
int testColor1 = 0; | |
int testColor2 = 0; | |
int testColor3 = 0; | |
int testColor4 = 0; | |
int testColor5 = 0; | |
bool moveEnd = false; | |
bool temp = true; | |
int fadeSpeed = 5; | |
void setup() { | |
// initialize the LED pins as an output: | |
pinMode(GREENledPin, OUTPUT); | |
pinMode(REDledPin, OUTPUT); | |
pinMode(BLUEledPin, OUTPUT); | |
// initialize the buttons as inputs: | |
pinMode(GREEN_Button, INPUT); | |
pinMode(RED_Button, INPUT); | |
pinMode(BLUE_Button, INPUT); | |
pinMode(VIOLET_Button, INPUT); | |
pinMode(ORANGE_Button, INPUT); | |
pinMode(YELLOW_Button, INPUT); | |
pinMode(MASTER_Button, INPUT); | |
Serial.begin(9600); | |
randomSeed(analogRead(A0)); | |
} | |
void loop() { | |
int GREEN_State = digitalRead(GREEN_Button); | |
int RED_State = digitalRead(RED_Button); | |
int BLUE_State = digitalRead(BLUE_Button); | |
int VIOLET_State = digitalRead(VIOLET_Button); | |
int ORANGE_State = digitalRead(ORANGE_Button); | |
int YELLOW_State = digitalRead(YELLOW_Button); | |
// Game OFF | |
if (gameState == 0) { | |
SetColor(0,0,0); | |
int masterState = digitalRead(MASTER_Button); | |
// if master button is pressed | |
if (masterState == HIGH) { | |
colorState = true; | |
delayRunning = true; | |
timeState = true; | |
gameState = 1; | |
temp = true; | |
int testColor0 = 0; | |
int testColor1 = 0; | |
int testColor2 = 0; | |
int testColor3 = 0; | |
int testColor4 = 0; | |
int testColor5 = 0; | |
int whichColor0 = 0; | |
int whichColor1 = 0; | |
int whichColor2 = 0; | |
int whichColor3 = 0; | |
int whichColor4 = 0; | |
int whichColor5 = 0; | |
} | |
// First Round | |
} else if (gameState == 1){ | |
if (timeState) { | |
delayStart = millis(); // start the delay | |
timeState = false; | |
} | |
if (colorState) { | |
whichColor0 = int(random(-0.5,5.9)); | |
whichColor1 = int(random(-0.5,5.9)); | |
whichColor2 = int(random(-0.5,5.9)); | |
} else { | |
whichColor0 = 6; | |
whichColor1 = 6; | |
whichColor2 = 6; | |
} | |
// Choosing the first three colors randomly | |
rounds[0] = whichColor0; | |
if (whichColor1 != 6 && whichColor1 == whichColor0) { | |
whichColor1 = int(random(-0.5,5.9)); | |
rounds[1] = whichColor1; | |
} else { | |
rounds[1] = whichColor1; | |
} | |
if ((whichColor2 != 6 && whichColor2 == whichColor1) || (whichColor2 != 6 && whichColor2 == whichColor0)) { | |
int temp = whichColor2; | |
whichColor2 = int(random(-0.5,5.9)); | |
while (temp == whichColor2) { | |
whichColor2 = int(random(-0.5,5.9)); | |
} | |
rounds[2] = whichColor2; | |
} else { | |
rounds[2] = whichColor2; | |
} | |
// Lighting up the neopixels | |
SetColor(randomColorPicker('G', rounds[0]),randomColorPicker('R', rounds[0]),randomColorPicker('B', rounds[0])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[1]),randomColorPicker('R', rounds[1]),randomColorPicker('B', rounds[1])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[2]),randomColorPicker('R', rounds[2]),randomColorPicker('B', rounds[2])); | |
delay(500); | |
// timer function | |
if (delayRunning && (millis() - delayStart >= 30000)) { | |
delayRunning = false; | |
gameState = 0; | |
} else { | |
if (colorState) { | |
testColor0 = whichColor0; | |
testColor1 = whichColor1; | |
testColor2 = whichColor2; | |
} | |
colorState = false; | |
if (temp) { | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
// First Button | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("First Button"); | |
Serial.print("\n"); | |
temp = false; | |
firstButton = true; | |
} | |
// Second Button | |
if (firstButton) { | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Second Button"); | |
Serial.print("\n"); | |
secondButton = true; | |
} | |
} | |
// Third Button | |
if (secondButton) { | |
if (colorToButton(testColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2 && colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3 && colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
gameState = 0; | |
} | |
if (colorToButton(testColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Third Button"); | |
Serial.print("\n"); | |
thirdButton = true; | |
} | |
} | |
if (firstButton && secondButton && thirdButton) { | |
Serial.print("First Round Passed"); | |
Serial.print("\n"); | |
Serial.print("\n"); | |
gameState = 2; | |
firstButton = false; | |
secondButton = false; | |
thirdButton = false; | |
colorState = true; | |
delayRunning = true; | |
timeState = true; | |
temp = true; | |
} | |
} | |
delay (1000); | |
// Second Round | |
} else if (gameState == 2) { | |
if (timeState) { | |
delayStart = millis(); // start the delay | |
timeState = false; | |
} | |
if (colorState) { | |
testColor3 = int(random(-0.5,5.9)); | |
} else { | |
testColor0 = 6; | |
testColor1 = 6; | |
testColor2 = 6; | |
testColor3 = 6; | |
} | |
// Importing the previous colors over | |
rounds[0] = testColor0; | |
rounds[1] = testColor1; | |
rounds[2] = testColor2; | |
if ((testColor3 != 6 && testColor3 == testColor0) || (testColor3 != 6 && testColor3 == testColor1) || (testColor3 != 6 && testColor3 == testColor2)) { | |
int temp = testColor3; | |
testColor3 = int(random(-0.5,5.9)); | |
while (temp == testColor3) { | |
testColor3 = int(random(-0.5,5.9)); | |
} | |
rounds[3] = testColor3; | |
} else { | |
rounds[3] = testColor3; | |
} | |
// Lighting up the neopixels | |
SetColor(randomColorPicker('G', rounds[0]),randomColorPicker('R', rounds[0]),randomColorPicker('B', rounds[0])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[1]),randomColorPicker('R', rounds[1]),randomColorPicker('B', rounds[1])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[2]),randomColorPicker('R', rounds[2]),randomColorPicker('B', rounds[2])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[3]),randomColorPicker('R', rounds[3]),randomColorPicker('B', rounds[3])); | |
delay(500); | |
// timer function | |
if (delayRunning && (millis() - delayStart >= 40000)) { | |
delayRunning = false; | |
gameState = 0; | |
} else { | |
if (colorState) { | |
whichColor0 = testColor0; | |
whichColor1 = testColor1; | |
whichColor2 = testColor2; | |
whichColor3 = testColor3; | |
} | |
colorState = false; | |
if (temp) { | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
// First Button | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("First Button"); | |
Serial.print("\n"); | |
temp = false; | |
firstButton = true; | |
} | |
// Second Button | |
if (firstButton) { | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Second Button"); | |
Serial.print("\n"); | |
secondButton = true; | |
} | |
} | |
// Third Button | |
if (secondButton) { | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Third Button"); | |
Serial.print("\n"); | |
thirdButton = true; | |
} | |
} | |
// Fourth Button | |
if (thirdButton) { | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Fourth Button"); | |
Serial.print("\n"); | |
fourthButton = true; | |
} | |
} | |
if (firstButton && secondButton && thirdButton && fourthButton) { | |
Serial.print("Second Round Passed"); | |
Serial.print("\n"); | |
Serial.print("\n"); | |
gameState = 3; | |
firstButton = false; | |
secondButton = false; | |
thirdButton = false; | |
fourthButton = false; | |
colorState = true; | |
delayRunning = true; | |
timeState = true; | |
temp = true; | |
} | |
} | |
delay (1000); | |
// Third Round | |
} else if (gameState == 3) { | |
if (timeState) { | |
delayStart = millis(); // start the delay | |
timeState = false; | |
} | |
if (colorState) { | |
whichColor4 = int(random(-0.5,5.9)); | |
} else { | |
whichColor0 = 6; | |
whichColor1 = 6; | |
whichColor2 = 6; | |
whichColor3 = 6; | |
whichColor4 = 6; | |
} | |
// Importing the previous colors over | |
rounds[0] = whichColor0; | |
rounds[1] = whichColor1; | |
rounds[2] = whichColor2; | |
rounds[3] = whichColor3; | |
if ((whichColor4 != 6 && whichColor4 == whichColor0) || (whichColor4 != 6 && whichColor4 == whichColor1) || (whichColor4 != 6 && whichColor4 == whichColor2) || (whichColor4 != 6 && whichColor4 == whichColor3)) { | |
int temp = whichColor4; | |
whichColor4 = int(random(-0.5,5.9)); | |
while (temp == whichColor4) { | |
whichColor4 = int(random(-0.5,5.9)); | |
} | |
rounds[4] = whichColor4; | |
} else { | |
rounds[4] = whichColor4; | |
} | |
// Lighting up the neopixels | |
SetColor(randomColorPicker('G', rounds[0]),randomColorPicker('R', rounds[0]),randomColorPicker('B', rounds[0])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[1]),randomColorPicker('R', rounds[1]),randomColorPicker('B', rounds[1])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[2]),randomColorPicker('R', rounds[2]),randomColorPicker('B', rounds[2])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[3]),randomColorPicker('R', rounds[3]),randomColorPicker('B', rounds[3])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[4]),randomColorPicker('R', rounds[4]),randomColorPicker('B', rounds[4])); | |
delay(500); | |
// timer function | |
if (delayRunning && (millis() - delayStart >= 50000)) { | |
delayRunning = false; | |
gameState = 0; | |
} else { | |
if (colorState) { | |
testColor0 = whichColor0; | |
testColor1 = whichColor1; | |
testColor2 = whichColor2; | |
testColor3 = whichColor3; | |
testColor4 = whichColor4; | |
} | |
colorState = false; | |
if (temp) { | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
// First Button | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("First Button"); | |
Serial.print("\n"); | |
temp = false; | |
firstButton = true; | |
} | |
// Second Button | |
if (firstButton) { | |
if (colorToButton(testColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Second Button"); | |
Serial.print("\n"); | |
secondButton = true; | |
} | |
} | |
// Third Button | |
if (secondButton) { | |
if (colorToButton(testColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(testColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(testColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Third Button"); | |
Serial.print("\n"); | |
thirdButton = true; | |
} | |
} | |
// Fourth Button | |
if (thirdButton) { | |
if (colorToButton(testColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(testColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(testColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Fourth Button"); | |
Serial.print("\n"); | |
fourthButton = true; | |
} | |
} | |
// Fifth Button | |
if (fourthButton) { | |
if (colorToButton(testColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(testColor4, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(testColor4, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Fifth Button"); | |
Serial.print("\n"); | |
fifthButton = true; | |
} | |
} | |
if (firstButton && secondButton && thirdButton && fourthButton && fifthButton) { | |
Serial.print("Third Round Passed"); | |
Serial.print("\n"); | |
Serial.print("\n"); | |
gameState = 4; | |
firstButton = false; | |
secondButton = false; | |
thirdButton = false; | |
fourthButton = false; | |
fifthButton = false; | |
colorState = true; | |
delayRunning = true; | |
timeState = true; | |
} | |
} | |
delay (1000); | |
// Fourth Round | |
} else if (gameState == 4) { | |
if (timeState) { | |
delayStart = millis(); // start the delay | |
timeState = false; | |
} | |
if (colorState) { | |
testColor5 = int(random(-0.5,5.9)); | |
} else { | |
testColor0 = 6; | |
testColor1 = 6; | |
testColor2 = 6; | |
testColor3 = 6; | |
testColor4 = 6; | |
testColor5 = 6; | |
} | |
// Importing the previous colors over | |
rounds[0] = testColor0; | |
rounds[1] = testColor1; | |
rounds[2] = testColor2; | |
rounds[3] = testColor3; | |
rounds[4] = testColor4; | |
if ((testColor5 != 6 && testColor5 == testColor0) || (testColor5 != 6 && testColor5 == testColor1) || (testColor5 != 6 && testColor5 == testColor2) || (testColor5 != 6 && testColor5 == testColor3) || (testColor5 != 6 && testColor5 == testColor4)) { | |
int temp = testColor5; | |
testColor5 = int(random(-0.5,5.9)); | |
while (temp == testColor5) { | |
testColor5 = int(random(-0.5,5.9)); | |
} | |
rounds[5] = testColor5; | |
} else { | |
rounds[5] = testColor5; | |
} | |
// Lighting up the neopixels | |
SetColor(randomColorPicker('G', rounds[0]),randomColorPicker('R', rounds[0]),randomColorPicker('B', rounds[0])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[1]),randomColorPicker('R', rounds[1]),randomColorPicker('B', rounds[1])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[2]),randomColorPicker('R', rounds[2]),randomColorPicker('B', rounds[2])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[3]),randomColorPicker('R', rounds[3]),randomColorPicker('B', rounds[3])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[4]),randomColorPicker('R', rounds[4]),randomColorPicker('B', rounds[4])); | |
delay(500); | |
SetColor(randomColorPicker('G', rounds[5]),randomColorPicker('R', rounds[5]),randomColorPicker('B', rounds[5])); | |
delay(500); | |
// timer function | |
if (delayRunning && (millis() - delayStart >= 60000)) { | |
delayRunning = false; | |
gameState = 0; | |
} else { | |
if (colorState) { | |
testColor0 = whichColor0; | |
testColor1 = whichColor1; | |
testColor2 = whichColor2; | |
testColor3 = whichColor3; | |
testColor4 = whichColor4; | |
testColor5 = whichColor5; | |
} | |
colorState = false; | |
if (temp) { | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
// First Button | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("First Button"); | |
Serial.print("\n"); | |
temp = false; | |
firstButton = true; | |
} | |
// Second Button | |
if (firstButton) { | |
if (colorToButton(whichColor0, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Second Button"); | |
Serial.print("\n"); | |
secondButton = true; | |
} | |
} | |
// Third Button | |
if (secondButton) { | |
if (colorToButton(whichColor1, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Third Button"); | |
Serial.print("\n"); | |
thirdButton = true; | |
} | |
} | |
// Fourth Button | |
if (thirdButton) { | |
if (colorToButton(whichColor2, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Fourth Button"); | |
Serial.print("\n"); | |
fourthButton = true; | |
} | |
} | |
// Fifth Button | |
if (fourthButton) { | |
if (colorToButton(whichColor3, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor4, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor4, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Fifth Button"); | |
Serial.print("\n"); | |
fifthButton = true; | |
} | |
} | |
// Sixth Button | |
if (fifthButton) { | |
if (colorToButton(whichColor4, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 3) { | |
if (colorToButton(whichColor5, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 2) { | |
gameState = 0; | |
} | |
} | |
if (colorToButton(whichColor5, GREEN_State, RED_State, BLUE_State, VIOLET_State, ORANGE_State, YELLOW_State) == 1) { | |
Serial.print("Sixth Button"); | |
Serial.print("\n"); | |
sixthButton = true; | |
} | |
} | |
if (firstButton && secondButton && thirdButton && fourthButton && fifthButton && sixthButton) { | |
Serial.print("Final Round Passed"); | |
Serial.print("\n"); | |
Serial.print("\n"); | |
gameState = 5; | |
firstButton = false; | |
secondButton = false; | |
thirdButton = false; | |
fourthButton = false; | |
fifthButton = false; | |
sixthButton = false; | |
colorState = true; | |
delayRunning = true; | |
timeState = true; | |
} | |
} | |
} else if (gameState == 5) { | |
Serial.print("Congratulations on completing the game!"); | |
Serial.print("\n"); | |
int masterState = digitalRead(MASTER_Button); | |
if (masterState == HIGH) { | |
gameState = 0; | |
} | |
int r, g, b; | |
// fade from blue to violet | |
for (r = 0; r < 256; r++) { | |
analogWrite(REDledPin, r); | |
delay(fadeSpeed); | |
} | |
// fade from violet to red | |
for (b = 255; b > 0; b--) { | |
analogWrite(BLUEledPin, b); | |
delay(fadeSpeed); | |
} | |
// fade from red to yellow | |
for (g = 0; g < 256; g++) { | |
analogWrite(GREENledPin, g); | |
delay(fadeSpeed); | |
} | |
// fade from yellow to green | |
for (r = 255; r > 0; r--) { | |
analogWrite(REDledPin, r); | |
delay(fadeSpeed); | |
} | |
// fade from green to teal | |
for (b = 0; b < 256; b++) { | |
analogWrite(BLUEledPin, b); | |
delay(fadeSpeed); | |
} | |
// fade from teal to blue | |
for (g = 255; g > 0; g--) { | |
analogWrite(GREENledPin, g); | |
delay(fadeSpeed); | |
} | |
} | |
} | |
void SetColor(char G,char R,char B) | |
{ | |
analogWrite(GREENledPin,G); | |
analogWrite(REDledPin,R); | |
analogWrite(BLUEledPin,B); | |
} | |
int randomColorPicker (char x, int whichColor) | |
{ | |
switch (whichColor) | |
{ | |
case 0: // Green | |
if (x == 'G') { | |
return colors[0]; | |
} else if (x == 'R') { | |
return colors[1]; | |
} else if (x == 'B') { | |
return colors[2]; | |
} | |
break; | |
case 1: // Red | |
if (x == 'G') { | |
return colors[3]; | |
} else if (x == 'R') { | |
return colors[4]; | |
} else if (x == 'B') { | |
return colors[5]; | |
} | |
break; | |
case 2: // Blue | |
if (x == 'G') { | |
return colors[6]; | |
} else if (x == 'R') { | |
return colors[7]; | |
} else if (x == 'B') { | |
return colors[8]; | |
} | |
break; | |
case 3: // Violet | |
if (x == 'G') { | |
return colors[9]; | |
} else if (x == 'R') { | |
return colors[10]; | |
} else if (x == 'B') { | |
return colors[11]; | |
} | |
break; | |
case 4: // Orange | |
if (x == 'G') { | |
return colors[12]; | |
} else if (x == 'R') { | |
return colors[13]; | |
} else if (x == 'B') { | |
return colors[14]; | |
} | |
break; | |
case 5: // Yellow | |
if (x == 'G') { | |
return colors[15]; | |
} else if (x == 'R') { | |
return colors[16]; | |
} else if (x == 'B') { | |
return colors[17]; | |
} | |
break; | |
case 6: // Off | |
if (x == 'G') { | |
return colors[18]; | |
} else if (x == 'R') { | |
return colors[19]; | |
} else if (x == 'B') { | |
return colors[20]; | |
} | |
break; | |
} | |
} | |
int colorToButton (int whichColor, int GREEN_State, int RED_State, int BLUE_State, int VIOLET_State, int ORANGE_State, int YELLOW_State) | |
{ | |
switch (whichColor) | |
{ | |
case 0: | |
if (GREEN_State == HIGH) { | |
SetColor(0, 255, 255); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (RED_State == HIGH || BLUE_State == HIGH || VIOLET_State == HIGH || ORANGE_State == HIGH || YELLOW_State == HIGH) { | |
return 2; | |
} else if (GREEN_State == LOW) { | |
return 3; | |
} | |
break; | |
case 1: | |
if (RED_State == HIGH) { | |
SetColor(255, 0, 255); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (GREEN_State == HIGH || BLUE_State == HIGH || VIOLET_State == HIGH || ORANGE_State == HIGH || YELLOW_State == HIGH) { | |
return 2; | |
} else if (RED_State == LOW) { | |
return 3; | |
} | |
break; | |
case 2: | |
if (BLUE_State == HIGH) { | |
SetColor(255, 255, 0); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (GREEN_State == HIGH || RED_State == HIGH || VIOLET_State == HIGH || ORANGE_State == HIGH || YELLOW_State == HIGH) { | |
return 2; | |
} else if (BLUE_State == LOW) { | |
return 3; | |
} | |
break; | |
case 3: | |
if (VIOLET_State == HIGH) { | |
SetColor(255, 10, 200); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (GREEN_State == HIGH || RED_State == HIGH || BLUE_State == HIGH || ORANGE_State == HIGH || YELLOW_State == HIGH) { | |
return 2; | |
} else if (VIOLET_State == LOW) { | |
return 3; | |
} | |
break; | |
case 4: | |
if (ORANGE_State == HIGH) { | |
SetColor(240, 10, 255); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (GREEN_State == HIGH || RED_State == HIGH || BLUE_State == HIGH || VIOLET_State == HIGH || YELLOW_State == HIGH) { | |
return 2; | |
} else if (ORANGE_State == LOW) { | |
return 3; | |
} | |
break; | |
case 5: | |
if (YELLOW_State == HIGH) { | |
SetColor(180, 10, 25); | |
delay(500); | |
SetColor(255,255,255); | |
return 1; | |
} else if (GREEN_State == HIGH || RED_State == HIGH || BLUE_State == HIGH || VIOLET_State == HIGH || ORANGE_State == HIGH) { | |
return 2; | |
} else if (YELLOW_State == LOW) { | |
return 3; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment