I am a complete newby at this, but trying to achieve a very specific goal.
I have an Arduino Nano and a WS2812B LED strip. I want to make it chase itself (this appears simple enough). I want to set its brightness (this also seems simple enough). But what I can't seem to get my head around is:
I want it to turn on at a low brightness with a push of a button. I then want to push the button again to make it brighter, and do this again 2 more times to increase the brightness each time.
I do not have the button/switch yet. As an electrician, wiring it in should be simple enough, but I do struggle with digital and its integration with programming.
Cheers ![]()
- In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the < CODE / > icon from the ‘posting menu’ to attach the copied sketch.
- Always show us a good schematic of your proposed circuit.
Show us good images of your ‘actual’ wiring. Give links to components.
A quick search for "arduino WS2812B" will turn up a whole lot of help!
Unless you write none blocking code, you will have to keep the button pressed until your program sees the button again, which, dependent on your code could be a long time.
So you need to step up your coding skills to be able to do this. There are lots of tutorials on line showing how to do this.
Try these two for a starters :-
Robin2's several things at once
http://forum.arduino.cc/index.php?topic=223286.0
Or Adafruit's
Describe this.
That sounds like four states.
255 is max beight. I would advise starting at "on" is value 51 + (4 * 51) = 255.
Show any code you have for reading a button.
Show how you wire the button.
Show how you debounce the button.
The WS2812 will be the easy part.
What is this obsession with de-bouncing a button? In most real programs it is not needed, especially here when the problem is going to be not being able to read the button fast enough anyway.
You call ONE mention of debounce an obsession?
It's bedtime, Mikey.
No, its morning here.
Not just you, in general a lot of members mention this and it is giving beginners a false impression of how important this is.
Cheers.
By Chase: Imagine a ball rolling along a channel. When it gets to the end it magically teleports back to the beginning and goes again. This happens indefinitely until a change is made. Now imagine the LEDs represent the ball, so they switch on and off in succession creating an "endless loop"
You are bang on! It is 4 states. The chase occurs identically in each state apart from the brightness.
Thanks for the brightness level advice. Really helpful.
Being completely illiterate in the area, I was just going to try the code from Arduino Push Button - Complete Tutorial - The Robotics Back-End for my button stuff, but I am struggling to make sense of it.
I know I am asking a lot. I got roped into doing sets for a community theatre group and I am trying to shortcut my way to a solution due to limited time. I do thank you for your useful advice so far ![]()
There are two WS2812B libraries that you will choose from (1) FastLED.h and (2) Adafruit_Neopixel.h Install both on your IDE.
Inside those libraries are examples. IDE >> FILE >> EXAMPLES >> (adafruit or fastled) >> (pick an example). Some examples are long, all-inclusive, and difficult to understand. Some examples are short and easy to understand. I prefer FastLED, but there is no difference in ease of use or function.
Here is an Adafruit example of a "ball rolling down a ramp and bouncing back." You can change the color, change the speed (see the comments). You can practice with the code at wokwi.com
#include <Adafruit_NeoPixel.h> // the name of the library
#define PIN 6 // pin for neopixel
#define NUMPIXELS 16 // number of neopixels
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); // "NUMPIXELS" and "PIN" are used here
int value = 100; // arbitrary delay value
bool j; // generic counter
void setup() {
pixels.begin(); // INITIALIZE neopixel
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
j = !j; // two cycles - j = 0 and j = 1
for (byte i = 0; i < NUMPIXELS; i++) { // For each pixel...
if (j) // if j == 1... do this...
pixels.setPixelColor(i, pixels.Color(0, 150, 0)); // pick a pixel {i} and a color (red, grn, blu)
else // if j == 0... do this...
pixels.setPixelColor((NUMPIXELS - 1) - i, pixels.Color(0, 255, 0)); // make it brighter
pixels.show(); // show the update
delay(value); // keep pixel on briefly
pixels.clear();
pixels.show(); // show the update
}
}
You will need to pay attention to the hardware setup and power supply. Adafruit does covers it extensively (search adafruit neopixel).
Do you mean something like my one dimensional Pong game?
The players have to bat the "ball" back when it arrives at your end?
Is yours something similar but you need the background to fade up and down at the same time in one of four colours?
Shouldn't be too hard.
Note while this was a project for the Raspberry Pi there is nothing stopping you using an Arduino and the C/C++ language that it uses.