I am working on a project where I have two buttons (inPinA & inPinB)
When you press the first button (inPinA) I want the brightness to increase on the NeoPixel Ring until it reaches the Maximum brightness. When you release the lights will decrease to the base level again (20)
When you press the second button (inPinB) I want the brightness to go to the maximum right away, and then when your release the button the lights will decrease back to the base level again (20)
I don't seem to have it quite right, so any assistance would be greatly appreciated
Code: Select all
void loop() {
strip.setPixelColor(12, lime);
strip.setPixelColor(13, lime);
strip.setPixelColor(14, lime);
strip.setPixelColor(15, lime);
strip.setPixelColor(16, lime);
//if button is pressed and we're under the max of 255 brightness,
if ( digitalRead(inPinA) == LOW && brightness < 256 ) brightness++;
//or if the button is released, and we are under the minimum 20 brightness,
else if ( digitalRead(inPinA) == HIGH && brightness > 20) {brightness--;} //-1, min of 0
if ( digitalRead(inPinB) == LOW && brightness < 256 ) brightness=256;
//or if the button is released, and we are under the minimum 20 brightness,
else if ( digitalRead(inPinB) == HIGH && brightness > 20) {brightness--;} //-1, min of 0
//do your animation stuff here, or re-set your pixels to full-values, in this example, full green.
for ( uint8_t i=0; i < 12; i++ ) strip.setPixelColor ( i, 0, 0, 255 );
//then update the overall strip brightness, as this function re-writes all color values as: pixel*(brightness/255) == dimmed pixel value;
strip.setBrightness ( brightness );
//then push the data to the pixels.
strip.show ();
//if you don't add some delay, the brightness will crawl up super fast
delay ( 15 );
}
Code: Select all
#include <Adafruit_NeoPixel.h>
#define PIN 3
#define yellow strip.Color(255,255,0)
#define green strip.Color(0,255,0)
#define blue strip.Color(0,0,255)
#define lime strip.Color(174,255,0)
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(17, PIN, NEO_GRB + NEO_KHZ800);
uint8_t brightness = 20; //global variable
//Button Push Setup
int inPinA = 4; // the number of the input pin (RX) - Button "A"
int current_stateA = HIGH; // the debounced input value
int inPinB = 8; // the number of the input pin (RX) - Button "A"
int current_stateB = HIGH; // the debounced input value
void setup() {
strip.begin();
strip.setBrightness ( brightness );
strip.setPixelColor(0, blue);
strip.setPixelColor(1, blue);
strip.setPixelColor(2, blue);
strip.setPixelColor(3, blue);
strip.setPixelColor(4, blue);
strip.setPixelColor(5, blue);
strip.setPixelColor(6, blue);
strip.setPixelColor(7, blue);
strip.setPixelColor(8, blue);
strip.setPixelColor(9, blue);
strip.setPixelColor(10, blue);
strip.setPixelColor(11, blue);
strip.setPixelColor(12, lime);
strip.setPixelColor(13, lime);
strip.setPixelColor(14, lime);
strip.setPixelColor(15, lime);
strip.setPixelColor(16, lime);
strip.show(); // Initialize all pixels to 'off'
pinMode(inPinA, INPUT_PULLUP);
pinMode(PIN, OUTPUT);
pinMode(inPinB, INPUT_PULLUP);
pinMode(PIN, OUTPUT);
}
void loop() {
strip.setPixelColor(12, lime);
strip.setPixelColor(13, lime);
strip.setPixelColor(14, lime);
strip.setPixelColor(15, lime);
strip.setPixelColor(16, lime);
//if button is pressed and we're under the max of 255 brightness,
if ( digitalRead(inPinA) == LOW && brightness < 256 ) brightness++;
//or if the button is released, and we are under the minimum 20 brightness,
else if ( digitalRead(inPinA) == HIGH && brightness > 20) {brightness--;} //-1, min of 0
if ( digitalRead(inPinB) == LOW && brightness < 256 ) brightness=256;
//or if the button is released, and we are under the minimum 20 brightness,
else if ( digitalRead(inPinB) == HIGH && brightness > 20) {brightness--;} //-1, min of 0
//do your animation stuff here, or re-set your pixels to full-values, in this example, full green.
for ( uint8_t i=0; i < 12; i++ ) strip.setPixelColor ( i, 0, 0, 255 );
//then update the overall strip brightness, as this function re-writes all color values as: pixel*(brightness/255) == dimmed pixel value;
strip.setBrightness ( brightness );
//then push the data to the pixels.
strip.show ();
//if you don't add some delay, the brightness will crawl up super fast
delay ( 15 );
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}