However, I would like to use a single Uno and not employ the IR nor sound reactive parts of the code. Basically I'd like it to simply cycle through the spectrum of colors and occasionally flash with the various types of lightning in the program.
I've spent 2 days trying to accomplish this to mixed results. I think I understand how to bypass the IR portions of the code, but my trouble is in triggering the lightning without the use of the sound reactivity/microphone.
I've come to the conclusion that it's beyond me to do so. I've started what for me will likely be the long journey of trying to learn to code from scratch, but I'm much better with the hardware than the software.
All that said, here is my question: Would it even be possible to use the code for the lightning from the project above triggered randomly?
The use of 'delay's has me questioning whether I'm wasting my time trying to adapt that part of the program. I'd love to have the two versions of code to compare to try to educate myself on the coding side of things, though that's probably asking a lot.
Let me be the first to say I know I should probably try to learn to code from the ground up, but I'm impatient and without a project to work on, find it hard to maintain interest in it.
Thank you in advance for any assistance you may offer, and for not punishing me too badly for asking this question here.
I for one do not wish to go to that github to look at the code, so how about you read the instructions for posting to post your best attempt at the code and explain what it does and does not do for you?
I don't currently have code that will compile, but I'll post what I have (there are probably issues with it besides not compiling):
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 50
#define DATA_PIN 9
int n, total = 30;
float average = 0;
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 30000; // interval at which to blink (milliseconds)
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
// this line sets the LED strip type - refer fastLED documeantion for more details https://github.com/FastLED/FastLED
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
void colour_fade() {
//mood mood lamp that cycles through colours
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue, 255, 255);
}
EVERY_N_MILLISECONDS(100) {
hue++;
}
FastLED.show();
}
void detect_thunder() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
//I've programmed 3 types of lightning. Each cycle, we pick a random one.
switch (random(1, 3)) {
//switch(3){
case 1:
thunderburst();
delay(random(10, 500));
break;
case 2:
rolling();
break;
case 3:
crack();
delay(random(50, 250));
break;
}
}
}
// utility function to turn all the lights off.
void reset() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV( 0, 0, 0);
}
FastLED.show();
}
void rolling() { // a simple method where we go through every LED with 1/10 chance
// of being turned on, up to 10 times, with a random delay wbetween each time
for (int r = 0; r < random(2, 10); r++) {
//iterate through every LED
for (int i = 0; i < NUM_LEDS; i++) {
if (random(0, 100) > 90) {
leds[i] = CHSV( 0, 0, 255);
}
else {
//dont need reset as we're blacking out other LEDs her
leds[i] = CHSV(0, 0, 0);
}
}
FastLED.show();
delay(random(5, 100));
reset();
}
}
void crack() {
//turn everything white briefly
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV( 0, 0, 255);
}
FastLED.show();
delay(random(10, 100));
reset();
}
void thunderburst() {
// this thunder works by lighting two random lengths
// of the strand from 10-20 pixels.
int rs1 = random(0, NUM_LEDS / 2);
int rl1 = random(10, 20);
int rs2 = random(rs1 + rl1, NUM_LEDS);
int rl2 = random(10, 20);
//repeat this chosen strands a few times, adds a bit of realism
for (int r = 0; r < random(3, 6); r++) {
for (int i = 0; i < rl1; i++) {
leds[i + rs1] = CHSV( 0, 0, 255);
}
if (rs2 + rl2 < NUM_LEDS) {
for (int i = 0; i < rl2; i++) {
leds[i + rs2] = CHSV( 0, 0, 255);
}
}
FastLED.show();
//stay illuminated for a set time
delay(random(10, 50));
reset();
delay(random(10, 50));
}
//}
}
(Getting a "a function-definition is not allowed here before '{' token" error, FYI)
I for one do not wish to go to that github to look at the code, so how about you read the instructions for posting to post your best attempt at the code and explain what it does and does not do for you?