// TITLE: Keypad Test #include #include #include #include #include // These are fixed variables #define NUM_LEDS 24 // number of Neopixels inj string CRGB leds[NUM_LEDS]; #define PIN 6 // Arduino data pin 6 out const byte ROWS = 4; // four rows const byte COLS = 3; // three columns char keys[ROWS][COLS] = { {'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}, {'#', '0', '*'} }; byte rowPins[ROWS] = {5, 4, 3, 2}; // connect to the row pinouts of the keypad byte colPins[COLS] = {9, 8, 7}; // connect to the column pinouts of the keypad int count = 0; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); /*int switchState = 0; // selector switch position int case 0 = 0; int case 1 = 0; int case 2 = 0; int case 3 = 0; int case 4 = 0; int case 5 = 0; int case 6 = 0; int case 7 = 0; int case 8 = 0; int case 9 = 0; int case 10 = 0; int case 11 = 0; int case 12 = 0;*/ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); void setup() { FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); pinMode(PIN, OUTPUT); strip.begin(); strip.show(); } // either or code void showStrip() { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.show(); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED FastLED.show(); #endif } void setPixel(int Pixel, byte red, byte green, byte blue) { #ifdef ADAFRUIT_NEOPIXEL_H // NeoPixel strip.setPixelColor(Pixel, strip.Color(red, green, blue)); #endif #ifndef ADAFRUIT_NEOPIXEL_H // FastLED leds[Pixel].r = red; leds[Pixel].g = green; leds[Pixel].b = blue; #endif } void loop() { char keys = keypad.getKey(); if (keys != NO_KEY) // Check for a valid key { switch (keys) { case 0: // Turns all LEDS to black colorWipe(strip.Color(0, 0, 0), 50); break; case 1: // First LED loop colorWipe(strip.Color(64, 0, 0), 125); // Red 125 is milliseconds per LED for move colorWipe(strip.Color(64, 64, 0), 125); // Red Green colorWipe(strip.Color(0, 64, 0), 125); // Green colorWipe(strip.Color(0, 64, 64), 125); // Green Blue colorWipe(strip.Color(0, 0, 64), 125); // Blue colorWipe(strip.Color(64, 0, 64), 125); // Blue Red colorWipe(strip.Color(0, 0, 64), 125); // Blue colorWipe(strip.Color(0, 64, 64), 125); // Green Blue colorWipe(strip.Color(0, 64, 0), 125); // Green colorWipe(strip.Color(64, 64, 0), 125); // Green Red colorWipe(strip.Color(64, 0, 0), 125); // Red colorWipe(strip.Color(0, 0, 0), 25); // Black/off break; case 2: colorWipe(strip.Color(64, 0, 0), 225); // Red 225 is milliseconds per LED for move colorWipe(strip.Color(64, 64, 64), 225); // White colorWipe(strip.Color(0, 0, 64), 225); // Blue colorWipe(strip.Color(64, 0, 0), 225); // Red colorWipe(strip.Color(64, 64, 64), 225); // White colorWipe(strip.Color(0, 0, 64), 225); // Blue colorWipe(strip.Color(0, 0, 0), 25); // Black/off break; case 3: colorWipe(strip.Color(64, 0, 0), 55); // Red as above colorWipe(strip.Color(64, 64, 0), 55); // Red Green colorWipe(strip.Color(0, 64, 0), 55); // Green colorWipe(strip.Color(0, 64, 64), 55); // Green Blue colorWipe(strip.Color(0, 0, 64), 55); // Blue colorWipe(strip.Color(64, 0, 64), 55); // Blue Red colorWipe(strip.Color(0, 0, 64), 55); // Blue colorWipe(strip.Color(0, 64, 64), 55); // Blue Green colorWipe(strip.Color(0, 64, 0), 55); // Green colorWipe(strip.Color(64, 64, 0), 55); // Green Red colorWipe(strip.Color(64, 0, 0), 55); // Red colorWipe(strip.Color(64, 64, 64), 110); // White colorWipe(strip.Color(64, 0, 0), 55); // Red colorWipe(strip.Color(64, 64, 0), 55); // Red Green colorWipe(strip.Color(0, 64, 0), 55); // Green colorWipe(strip.Color(0, 64, 64), 55); // Green Blue colorWipe(strip.Color(0, 0, 64), 55); // Blue colorWipe(strip.Color(64, 0, 64), 55); // Blue Red colorWipe(strip.Color(0, 0, 64), 55); // Blue colorWipe(strip.Color(0, 64, 64), 55); // Green Blue colorWipe(strip.Color(0, 64, 0), 55); // Green colorWipe(strip.Color(64, 64, 0), 55); // Green Red colorWipe(strip.Color(64, 0, 0), 55); // Red colorWipe(strip.Color(0, 0, 0), 25); // Black/off break; case 4: theaterChase(strip.Color(127, 0, 0), 250); // Full Red theaterChase(strip.Color(127, 127, 127), 250); // White theaterChase(strip.Color(0, 0, 127), 250); // Full Blue colorWipe(strip.Color(0, 0, 0), 15); // Black/off break; case 5: rainbow(130); // 20 increased to 130 to extend time colorWipe(strip.Color(0, 0, 0), 15); // Black/off break; case 6: rainbowCycle(30); // 20 increased to 30 to extend time colorWipe(strip.Color(0, 0, 0), 15); // Black/off break; case 7: theaterChaseRainbow(42); // 50 dropped to 42 to shorten time colorWipe(strip.Color(0, 0, 0), 15); // Black/off break; default: // Turns all LEDS to black colorWipe(strip.Color(0, 0, 0), 50); break; } } } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for (uint16_t i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } void rainbow(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256; j++) { for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i + j) & 255)); } strip.show(); delay(wait); } } // Slightly different, this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for (j = 0; j < 256 * 4; j++) { // 5 cycles of all colors on wheel, changed to 4 for length for (i = 0; i < strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } //Theatre-style crawling lights. void theaterChase(uint32_t c, uint8_t wait); for (int j = 0; j < 15; j++) { //do 10 cycles of chasing, changed to 15 for length for (int q = 0; q < 3; q++) { for (int i = 0; i < strip.numPixels(); i = i + 3) { strip.setPixelColor(i + q, c); //turn every third pixel on } strip.show(); delay(wait); for (int i = 0; i < strip.numPixels(); i = i + 3) { strip.setPixelColor(i + q, 0); //turn every third pixel off } } } //Theatre-style crawling lights with rainbow effect void theaterChaseRainbow(uint8_t wait) { for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q = 0; q < 3; q++) { for (int i = 0; i < strip.numPixels(); i = i + 3) { strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on } strip.show(); delay(wait); for (int i = 0; i < strip.numPixels(); i = i + 3) { strip.setPixelColor(i + q, 0); //turn every third pixel off } } } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if (WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if (WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); }