Last active
June 3, 2016 16:19
-
-
Save antila/1fd874295eb18a9b4bf37887050bc43b to your computer and use it in GitHub Desktop.
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
#include <Adafruit_NeoPixel.h> | |
// Which pin on the Arduino is connected to the NeoPixels? | |
#define PIN 6 | |
// How many NeoPixels are attached to the Arduino? | |
#define NUM_LEDS 60 | |
// How much the light should dim per loop | |
#define falloff 1 | |
// How much each "spread" should dim | |
#define spreadFalloff 40 | |
// Delay between each loop | |
#define delayval 1 | |
int leds[NUM_LEDS]; | |
int ledsUpdate[NUM_LEDS]; | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("setup_thunder"); | |
for(int i=0; i < NUM_LEDS; i++){ | |
leds[i] = 0; | |
ledsUpdate[i] = 0; | |
} | |
strip.begin(); | |
} | |
void loop() { | |
int r = random(1, 200); | |
if (r == 1) { | |
int l = random(0, NUM_LEDS); | |
leds[l] = 255; | |
} | |
// Save current value | |
memcpy(ledsUpdate, leds, sizeof(leds)); | |
// Update values | |
for(int i = 0; i < NUM_LEDS; i++){ | |
int nextLed = i + 1; | |
int previousLed = i - 1; | |
int newValue = leds[i] - spreadFalloff; | |
if (nextLed >= NUM_LEDS) { | |
nextLed = 0; | |
} | |
if (previousLed <= 0) { | |
previousLed = NUM_LEDS; | |
} | |
if (ledsUpdate[previousLed] < newValue) { | |
ledsUpdate[previousLed] = newValue; | |
} | |
if (ledsUpdate[i] < leds[i]) { | |
ledsUpdate[i] = leds[i]; | |
} | |
if (ledsUpdate[nextLed] < newValue) { | |
ledsUpdate[nextLed] = newValue; | |
} | |
} | |
// Remove negative numbers | |
for(int i=0;i<NUM_LEDS;i++){ | |
ledsUpdate[i] = ledsUpdate[i] - falloff; | |
if (ledsUpdate[i] < 0) { | |
ledsUpdate[i] = 0; | |
} | |
if (leds[i] < 0) { | |
leds[i] = 0; | |
} | |
} | |
// Save updated numbers | |
memcpy(leds, ledsUpdate, sizeof(ledsUpdate)); | |
/* | |
for(int i=0;i<NUM_LEDS;i++){ | |
int value = ledsUpdate[i]; | |
if (value < 10 && value >= 0) { | |
Serial.print(0); | |
} | |
Serial.print(value); | |
Serial.print(", "); | |
} | |
Serial.print(" "); | |
for(int i=0;i<NUM_LEDS;i++){ | |
int value = leds[i]; | |
if (value < 10 && value >= 0) { | |
Serial.print(0); | |
} | |
Serial.print(value); | |
Serial.print(", "); | |
} | |
Serial.println(""); | |
*/ | |
// Show it | |
for(int i=0;i<NUM_LEDS;i++){ | |
int value = leds[i]; | |
strip.setPixelColor(i, strip.Color(value / 4, 0, value)); | |
} | |
strip.show(); | |
delay(delayval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment