Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
I used 2 digital pins for LED1 and LED2, instead of the Analog pins.
The meteor function is called 5 times with a for-loop in "void loop()".
Changed the analogPin and ledPIn1/2 to "#define" calls, so things take up less memory.
Reformatted the code a little for readability (always a good idea).
I optimized some code since you're using FastLED anyway ... 😊
The code below had NOT been tested, so things may not work as hoped for, since I do not have the hardware handy ... 😊
Let me know how it worked ...
You stay healthy as well! 😉
/* LDR triggered LED Strip with WS2812B and LED effect "Meteor Rain" (Tweaking4All) */
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#define NUM_LEDS 105
CRGB leds[NUM_LEDS];
#define PIN 6
// Used Define since that does not take up any memory
#define analogPin A0 // LDR pin
#define ledPin1 12 // digital pin that the green LED is attached to
#define ledPin2 13 // digital pin that the yellow LED is attached to
#define threshold 500 // an arbitrary threshold level that's in the range of the analog input
void setup() {
FastLED.addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
// initialize the LED pins for output:
// Note: I picked 2 digital pins for this (#12 and #13) instead of the analog pins you used!
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LDR an PIN A0
pinMode(analogPin, INPUT);
// Initialize serial monitor/port
Serial.begin(9600);
}
void loop() {
// read the value of the ldr:
int analogValue = analogRead(analogPin);
// Did something pass the LDR (= dark?)
if (analogValue < threshold) {
Serial.println("MARBLE PASSED LDR <------");
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
// run meteor rain 5x
for(int i; i<5; i++) {
meteorRain(0xff, 0xff, 0xff, 10, 50, true, 30);
}
} else {
Serial.println("LDR Did not detect anything");
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
}
delay(50); // delay in between reads for stability
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
for (int i = 0; i < NUM_LEDS + NUM_LEDS; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < NUM_LEDS; j++) {
if ((!meteorRandomDecay) || (random(10) > 5)) {
leds[j].fadeToBlackBy(meteorTrailDecay);
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ((i - j < NUM_LEDS) && (i - j >= 0)) {
leds[i - j] = CRGB(red, green, blue);
}
}
FastLED.show();
delay(SpeedDelay);
}
}
I'm not sure where the "=0" is supposed to be placed (I need more coffee to wake up haha). Would you mind posting the full code - this way others may benefit from it as well 😊
It is an element in my fischertechnik marble track. The ball triggers the LDR which starts the sketch on the NANO. Then the Meteor Rain runs 5 times and the module is ready for the next triggering.
Sounds simple? Well, the devil is in the details!
First you have to calibrate the LDR. Depending on the light emission of the LED used and the surrounding light, the resistance of the LDR differs.
So it has to be checked with the serial monitor using an analog output. Depending on that the threshold has to be defined. In this case it is 850.
For the lightbeams I use LEDs between 10000 and 20000 mcd in red. They usually work sufficient.
The green LED indicates the Ready Status of the circuit, the orange one indicates triggering. So if something is wrong you know where to check.
When you load the sketch to the Arduino DISCONNECT the LED strip. Otherwise the Arduino tries to power the strip. With 105 LEDs the Arduino goes up in smoke!
Happy New Year! 😮
And put a 1000uF capacitator between VCC and GND of the powersupply. It protects the strip.
Additionally the resistor for the dataline of the strip is neccessary. The values differ between 330 and 470. Both should be fine.
I split up the strip to create an impact area of 20 LEDs. That meant A LOT of soldering but it was worth it! Be sure to solder VERY preciselly for the soldering points on the
WS2812 are very tiny and lots of short circuits are at hand 🤐
The code is not too complex. Anyway, I needed Hans´ help. Again. Thank you Hans. You are the man! 👍
Any questions? Post ´em.
Have fun!
Thomas
/* LDR triggered LED Strip with WS2812B and LED effect "Meteor Rain" (Tweaking4All) */
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include "FastLED.h"
#define NUM_LEDS 105
CRGB leds[NUM_LEDS];
#define PIN 6
// Used Define since that does not take up any memory
#define analogPin A0 // LDR pin
#define ledPin1 12 // digital pin that the green LED is attached to
#define ledPin2 13 // digital pin that the yellow LED is attached to
#define threshold 850 // an arbitrary threshold level that's in the range of the analog input
void setup() {
FastLED.addLeds < WS2811, PIN, GRB > (leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
// initialize the LED pins for output:
// Note: I picked 2 digital pins for this (#12 and #13) instead of the analog pins you used!
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// LDR an PIN A0
pinMode(analogPin, INPUT);
// Initialize serial monitor/port
Serial.begin(9600);
}
void loop() {
// read the value of the ldr:
int analogValue = analogRead(analogPin);
// Did something pass the LDR (= dark?)
if (analogValue < threshold) {
Serial.println("MARBLE PASSED LDR <------");
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
// run meteor rain 5x
for(int i=0; i<5; i++) {
// meteorRain(0xff, 0xff, 0xff, 10, 50, true, 30);
// colour RED:
meteorRain(255, 48, 48, 10, 50, true, 30);
// hot pink
// meteorRain(255, 110, 180, 10, 50, true, 30);
}
} else {
Serial.println("LDR Did not detect anything");
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
}
delay(50); // delay in between reads for stability
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
// All LEDs black
fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
FastLED.show();
for (int i = 0; i < NUM_LEDS + NUM_LEDS; i++) {
// fade brightness all LEDs one step
for (int j = 0; j < NUM_LEDS; j++) {
if ((!meteorRandomDecay) || (random(10) > 5)) {
leds[j].fadeToBlackBy(meteorTrailDecay);
}
}
// draw meteor
for (int j = 0; j < meteorSize; j++) {
if ((i - j < NUM_LEDS) && (i - j >= 0)) {
leds[i - j] = CRGB(red, green, blue);
}
}
FastLED.show();
delay(SpeedDelay);
}
}
7-Zip One of the best, free, and most efficient Windows archive and unarchive utilties around. Support quite a few formats as well.
HandBrake Great tool for ripping DVD's and converting video.
VueScan Ultimate scanning tool for Windows, Linux, and macOS, supporting pretty much any scanner, even those no longer supported by your OS. (no scanner drivers needed!)
WordPress WordPress is one of the best tools for Blogs and Content Management Systems.
Start-is-Back Ultimate Start-button replacement for Windows 8 and 8.1 - Super cheap, but highly recommended.
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).