Hello!
I was wondering if anyone here has experience or would know anything about programming the rate of blinking of an Adafruit RGB Led Strip with a potentiometer knob.
Any help or links are greatly appreciated; thank you!
Hello!
I was wondering if anyone here has experience or would know anything about programming the rate of blinking of an Adafruit RGB Led Strip with a potentiometer knob.
Any help or links are greatly appreciated; thank you!
Have you already got code to make the LED strip blink at a fixed rate ? If so, then please post it here.
All I have is this piece of code that I can't seem to get to work with all 60 LED's ( on my strip ) but only the first one.
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 60
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 6
#define CLOCK_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
// Turn the LED on, then pause
leds[0] = CRGB::Red;
FastLED.show();
delay(500);
// Now turn the LED off, then pause
leds[0] = CRGB::Black;
FastLED.show();
delay(500);
}
leds[0] = CRGB::Red;Looks like it only turns on one LED.
I am not familiar with the library but would expect this to turn on all of the LEDs
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::Red;
}
FastLED.show();
Try it. Don't forget that you have to turn them all off again. If it works then we can discuss changing the rate at which they blink.
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 60
#define DATA_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
;
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::Red;
}
FastLED.show();
delay(500);
{
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::Black;
}
FastLED.show();
delay(500);
}
}
Works perfectly!
Works perfectly!
Good. Do you know how and why it works ?
Time to tackle varying the rate of blinking. There is a "dirty" way using delay() and a "clean" way using millis(). Both require the pot value to be determined by using analogRead(). Do you know how to do that ?
I do but as much as I have tried using it with this piece of code, I can't seem to get it working. I have a potentiometer already hooked up to A0. I will also replace the delay with milliseconds; thank you!
I will also replace the delay with milliseconds; thank you!
Can I suggest that you start with the "dirty" method.
Replace the fixed value of 500 in the delay()s with a variable. Connect the pot to 5V, GND (end connections) and an analogue pin and read the value into the variable used in the delay. Varying the pot position will vary the blink frequency.
You need to look into using millis() for timing as in the BlinkWithoutDelay example and Several things at the same time
Save the time the blink starts then each time through loop() check whether the required period has elapsed since it started. If not then go round loop() again reading inputs etc. If the period has elapsed then take the required action, ie flip the state of the LEDs and note the start time again. This will be easier if you put the LED on and off code in 2 functions that you can call from loop() at the appropriate time.
I tried replacing the delay with value but was unable to get it working; could you by any chance help me do this? Thank you!
debob7:
I tried replacing the delay with value but was unable to get it working; could you by any chance help me do this? Thank you!
Please post the code that you tried and confirm how the pot is wired.
The pot is wired to analog pin A0. I tried experimenting with using and if else statement but I keep getting an error that x is not defined, which did not exist before. I have tried to get rid of this error but have had no luck sadly. Here is the code I have been experimenting with. (There is another part with the LED pin 13 set to high that controls another light; ignore that.)
#include "FastLED.h"
#define NUM_LEDS 60
#define DATA_PIN 6
#include <MyoController.h>
MyoController myo = MyoController();
int blink = 500;
int val;
int potpin = 0;
int elPin = 13;
int sensorvalue = 0;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
pinMode(elPin, OUTPUT);
myo.initMyo();
}
void loop() {
{
if (sensorvalue >= x++) { //Compare analog value with threshold
}
{
leds[x] = CRGB::White;
}
FastLED.show();
delay(val);
}
else {
leds[x] = CRGB::Black;
}
FastLED.show();
delay(val);
{
digitalWrite(elPin, HIGH);
}
Did you try defining x?
I did but did not have any luck. Weird thing is it was working before without defining X; now it's giving me this error. I assume it may also be a bracketing error but since I am not fluid with Arduino I have no idea how to fix it.
finally got it; thanks guys!
#include "FastLED.h"
#define NUM_LEDS 60
#define DATA_PIN 6
int blink = 500;
int val;
int potpin = 0;
int elPin = 13;
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
;
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
pinMode(elPin, OUTPUT);
}
void loop() {
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 500, 5);
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::White;
}
FastLED.show();
delay(val);
{
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::Black;
}
FastLED.show();
delay(val);
}
}
{
{
digitalWrite(elPin, HIGH);
}
}
}
Your code may work but there is something awfully wrong with the use of braces. I have taken the liberty of editing your code to put each opening and closing brace on its own line.
void setup()
{
;
What is that semicolon doing there ?
void loop()
{
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Why two braces at the start of the loop() function ?
{
for (int x = 0; x < NUM_LEDS ; x++)
{
leds[x] = CRGB::Black;
}
FastLED.show();
delay(val);
}
What are the pair of outer braces for ?
{
{
digitalWrite(elPin, HIGH);
}
}
More double sets of braces where none is required. Also you never set elPin LOW. This may be what you want but I doubt it.