#include #include #include #include #define PIN 5 #define NUMPIXELS 256 SoftwareSerial mySerial(1, 0); enum States { START, FULL, EPI }; enum States state; const int ledPin = 7; const int buttonPin = 10; const int potPin = A1; const int matrixWidth = 8; const int matrixHeight = 8; const int tileWidth = 4; const int tileHeight = 1; int buttonState = 0; const int screenWidth = matrixWidth * tileWidth; const int screenHeight = matrixHeight * tileHeight; int value; String command; Adafruit_NeoMatrix screen = Adafruit_NeoMatrix( matrixWidth, matrixHeight, tileWidth, tileHeight, PIN, NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS + NEO_TILE_PROGRESSIVE + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE, NEO_GRBW + NEO_KHZ800); const uint16_t colors[] = { screen.Color(255, value, 0), screen.Color(0 , 255, value), screen.Color(value, 0, 255) }; uint16_t c; int x = 0; int y = 0; void setup() { CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); mySerial.begin(9600); screen.begin(); screen.setBrightness(20); screen.clear(); screen.show(); startRoutine(); pinMode (ledPin, OUTPUT); pinMode (buttonPin, INPUT); state = START; mySerial.println(state); } void loop() { value = analogRead(potPin); if (value > 0 && value < 400) { c = colors[0]; state = FULL; mySerial.println("Red"); } else if (value >= 400 && value < 800) { c = colors[1]; state = FULL; mySerial.println("Green"); } else if (value >= 800 && value <= 1023) { c = colors[2]; state = FULL; mySerial.println("Blue"); } else { state = START; safeguard(); } buttonState = digitalRead(buttonPin); if (buttonState == LOW) { state = EPI; } switch (state) { case EPI: epilepsy(); break; case FULL: for (int i = 0; i < screenHeight; i++) { for (int k = 0; k < screenWidth; k += 1) { screen.drawPixel(k, i, c); screen.show(); } } break; screen.clear(); default: break; } screen.show(); } void safeguard() { screen.clear(); screen.show(); } void epilepsy() { mySerial.println("Epilepsy begun"); screen.clear(); for (int i = 0; i < screenHeight; i++) { for (int k = 0; k < screenWidth; k += 1) { screen.drawPixel(k, i, screen.Color(255, value, value)); } } screen.show(); delay(50); screen.clear(); for (int i = 0; i < screenHeight; i++) { for (int k = 0; k < screenWidth; k += 1) { screen.drawPixel(k, i, screen.Color(value, value, 255)); } } screen.show(); delay(50); mySerial.println("Epilepsy begone"); } void startRoutine() { mySerial.println("Make it so!"); screen.clear(); for (int i = 0; i < screenHeight; i++) { for (int k = 0; k < screenWidth; k += 4) { screen.drawPixel(k, i, screen.Color(255, 255, 255)); screen.show(); } } for (int i = 0; i < screenHeight; i++) { for (int k = 0; k < screenWidth; k += 1) { screen.drawPixel(k, i, screen.Color(0, 0, 0)); } } screen.show(); mySerial.println("Ahoy!"); }