Components and supplies
PIR Motion Sensor (generic)
Relay (generic)
Arduino Nano R3
8x8 Neopixel Panel
PC PSU Power Cord
Arduino UNO
Jumper wires (generic)
RGB LED Strip
Tools and machines
Soldering iron (generic)
Wire Stripper
Project description
Code
Arduino Holiday
arduino
1#include <FastLED.h> 2 3FASTLED_USING_NAMESPACE 4 5#include <Adafruit_GFX.h> 6#include <Adafruit_NeoMatrix.h> 7#include <Adafruit_NeoPixel.h> 8#ifndef PSTR 9#define PSTR // Make Arduino Due happy 10#endif 11#define PIN 6 12//#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000) 13//#warning "Requires FastLED 3.1 or later; check github for latest code." 14//#endif 15 16#define DATA_PIN 6 17#define LED_TYPE WS2811 18#define COLOR_ORDER GRB 19#define NUM_LEDS 192 20CRGB leds[NUM_LEDS]; 21const uint8_t kMatrixWidth = 24; 22const uint8_t kMatrixHeight = 8; 23const bool kMatrixSerpentineLayout = true; 24#define NUM_LEDS (kMatrixWidth * kMatrixHeight) 25#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight) 26#define BRIGHTNESS 50 27#define FRAMES_PER_SECOND 120 28// The 16 bit version of our coordinates 29static uint16_t x; 30static uint16_t y; 31static uint16_t z; 32Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(24, 8, PIN, 33 NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + 34 NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, 35 NEO_GRB + NEO_KHZ800); 36const uint16_t colors[] = { 37 matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 0, 255), matrix.Color(255, 255, 0), matrix.Color(255, 255, 255)}; 38uint16_t speed = 20; // speed is set dynamically once we've started up 39uint16_t scale = 30; // scale is set dynamically once we've started 40uint8_t noise[MAX_DIMENSION][MAX_DIMENSION]; 41CRGBPalette16 currentPalette( PartyColors_p ); 42uint8_t colorLoop = 1; 43int pirSensorPin = 5; // choose the input pin (for PIR sensor) 44int pirState = true; // we start, assuming no motion detected 45int val = 0; // variable for reading the pin status 46int minimummSecsLowForInactive = 5000; // If the sensor reports low for 47// more than this time, then assume no activity 48long unsigned int timeLow; 49boolean takeLowTime; 50 51//the time we give the sensor to calibrate (10-60 secs according to the datasheet) 52int calibrationTime = 30; 53 54void setup() { 55 delay(3000); // 3 second delay for recovery 56 57 // tell FastLED about the LED strip configuration 58 FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); 59 //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); 60 61 // set master brightness control 62 FastLED.setBrightness(BRIGHTNESS); 63 matrix.setTextWrap(false); 64 matrix.setBrightness(40); 65 matrix.setTextColor(colors[0]); 66 pinMode(pirSensorPin, INPUT); // declare sensor as input 67 LEDS.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); 68 x = random16(); 69 y = random16(); 70 z = random16(); 71} 72int a = matrix.width(); 73int pass = 0; 74 75// List of patterns to cycle through. Each is defined as a separate function below. 76typedef void (*SimplePatternList[])(); 77SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm, cylon}; 78 79uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current 80uint8_t gHue = 0; // rotating "base color" used by many of the patterns 81 82void fadeall() { 83 for (int i = 0; i < NUM_LEDS; i++) { 84 leds[i].nscale8(250); 85 } 86} 87 88void loop() 89{ 90 val = digitalRead(pirSensorPin); // read input value 91 if (val == HIGH) { // check if the input is HIGH 92 93 matrix.fillScreen(1); 94 matrix.setCursor(a, 0); 95 matrix.print(F("Happy Holidays & Happy New Year!")); 96 if (--a < -200) { 97 a = matrix.width(); 98 if (++pass >= 6) pass = 0; 99 matrix.setTextColor(colors[pass]); 100 } 101 matrix.show(); 102 delay(100); 103 if (pirState) { 104 // we have just turned on 105 pirState = false; 106 107 } 108 takeLowTime = true; 109 } 110 else { 111 112 // Call the current pattern function once, updating the 'leds' array 113 gPatterns[gCurrentPatternNumber](); 114 115 // send the 'leds' array out to the actual LED strip 116 FastLED.show(); 117 // insert a delay to keep the framerate modest 118 FastLED.delay(1000 / FRAMES_PER_SECOND); 119 120 // do some periodic updates 121 EVERY_N_MILLISECONDS( 20 ) { 122 gHue++; // slowly cycle the "base color" through the rainbow 123 } 124 EVERY_N_SECONDS( 10 ) { 125 nextPattern(); // change patterns periodically 126 } 127 128 } 129} 130#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) 131 132void nextPattern() 133{ 134 // add one to the current pattern number, and wrap around at the end 135 gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); 136} 137 138void rainbow() 139{ 140 // FastLED's built-in rainbow generator 141 fill_rainbow( leds, NUM_LEDS, gHue, 7); 142} 143 144 145void rainbowWithGlitter() 146{ 147 // built-in FastLED rainbow, plus some random sparkly glitter 148 rainbow(); 149 addGlitter(80); 150} 151 152void addGlitter( fract8 chanceOfGlitter) 153{ 154 if ( random8() < chanceOfGlitter) { 155 leds[ random16(NUM_LEDS) ] += CRGB::White; 156 } 157} 158 159void confetti() 160{ 161 // random colored speckles that blink in and fade smoothly 162 fadeToBlackBy( leds, NUM_LEDS, 10); 163 int pos = random16(NUM_LEDS); 164 leds[pos] += CHSV( gHue + random8(64), 200, 255); 165} 166 167void sinelon() 168{ 169 // a colored dot sweeping back and forth, with fading trails 170 fadeToBlackBy( leds, NUM_LEDS, 20); 171 int pos = beatsin16( 13, 0, NUM_LEDS - 1 ); 172 leds[pos] += CHSV( gHue, 255, 192); 173} 174 175void bpm() 176{ 177 // colored stripes pulsing at a defined Beats-Per-Minute (BPM) 178 uint8_t BeatsPerMinute = 62; 179 CRGBPalette16 palette = PartyColors_p; 180 uint8_t beat = beatsin8( BeatsPerMinute, 64, 255); 181 for ( int i = 0; i < NUM_LEDS; i++) { //9948 182 leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10)); 183 } 184} 185 186void juggle() { 187 // eight colored dots, weaving in and out of sync with each other 188 fadeToBlackBy( leds, NUM_LEDS, 20); 189 byte dothue = 0; 190 for ( int i = 0; i < 8; i++) { 191 leds[beatsin16( i + 7, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255); 192 dothue += 32; 193 } 194} 195 196void cylon() { 197static uint8_t hue = 0; 198 // First slide the led in one direction 199 for(int i = 0; i < NUM_LEDS; i++) { 200 // Set the i'th led to red 201 leds[i] = CHSV(hue++, 255, 255); 202 // Show the leds 203 FastLED.show(); 204 // now that we've shown the leds, reset the i'th led to black 205 // leds[i] = CRGB::Black; 206 fadeall(); 207 // Wait a little bit before we loop around and do it again 208 delay(10); 209 } 210 211 // Now go in the other direction. 212 for(int i = (NUM_LEDS)-1; i >= 0; i--) { 213 // Set the i'th led to red 214 leds[i] = CHSV(hue++, 255, 255); 215 // Show the leds 216 FastLED.show(); 217 // now that we've shown the leds, reset the i'th led to black 218 // leds[i] = CRGB::Black; 219 fadeall(); 220 // Wait a little bit before we loop around and do it again 221 delay(10); 222 } 223} 224
Downloadable files
simple schematic
simple schematic
simple schematic
simple schematic
Comments
Only logged in users can leave comments
Heathen_Hacks-v2
0 Followers
•0 Projects
Table of contents
Intro
17
0