I also want to add 2 or 3 buttons
I want these specific Buttons and set them up to control specific color settings of my choice
Not sure what would be best, Momentary or Latching
Thank you, can you help me make a few changes please with coding, I want to have 3 total buttons, 1 for Red, 2 for White, and 3 for completley random addressable colors to change.
Ok so I took your advice, and have been doing alot of research, unfortunalty I couldn't figure out how to code the ezButton you suggested however you did give me a lot of different ideas I wasn't aware of before, so after many hours of trying to code this is what I came up with, 2 buttons basically one to change LEDs to Red and the other button to White, if you can please tell me how I can code the press and hold the "Red" button to make brightness higher and click and hole "White" button to dim. Here's my code which works fine without brightness.
Thanks again for all your help
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
#define RED 2
#define WHITE 3
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 16 // Number of NeoPixels
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9
void setup() {
pinMode(RED, INPUT_PULLUP);
pinMode(WHITE, INPUT_PULLUP);
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'
pinMode(PIXEL_PIN, OUTPUT);
// init serialize communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Get current button state.
boolean newState = digitalRead(RED);
boolean newState2 = digitalRead(WHITE);
// Check if state changed from high to low (button press).
if((newState == LOW) && (oldState == HIGH)) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(RED);
if(newState == LOW) { // Yes, still low
if(++mode > 0) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation...
case 0:
colorWipe(strip.Color( 255, 0, 0), 50); // Red
break;
}
}
}
// Check if state changed from high to low (button press).
if((newState2 == LOW) && (oldState == HIGH)) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState2 = digitalRead(WHITE);
if(newState2 == LOW) { // Yes, still low
if(++mode > 1) mode = 0; // Advance to next mode, wrap around after #8
switch(mode) { // Start the new animation...
case 0:
colorWipe(strip.Color(255, 255, 255), 50); // White
break;
}
}
}
// Set the last-read button state to the old state.
oldState= newState;
}
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
type or paste code here
Your button press is using "delay()" to debounce the button which will get in the way of timing needed for the long press to work. Take a look at a few "arduino button short press long press" and compare their methods They usually start a timer when the button is pressed, then use the timer to determine if the bouncing is done, then keep track of how long the button has been pressed to determine short or long press.