Hello!
I have a quite few questions but I'll start with 3 small ones.
keep in mind that i am Jon Snow when it comes to programming, I know nothing
-
I modified the neopixel button cycle sketch from Adafruit to cycle from off, to Blue, to Orange. then loop (i'm making a portal gun). when i power up the Arduino or update the code it starts in cycle 1, Blue, instead of starting in the off position on cycle 0. code is below. How would i go about fixing that? should i just make cycle 1 the off position?
-
I found this library called clickbutton. I'm still not sure how to use libraries or how to code an Arduino, or how to code. In the example sketch, the button is an analog input but in my code the button is a debounced digital input. Does it matter if its an analog or digital input?
-
How would i go about using clickbutton in my sketch to control the neopixel ring?
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 6 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 12
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
// 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(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 2)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 0); // Black/off
break;
case 1: colorWipe(strip.Color(0, 0, 255), 0); // Blue
break;
case 2: colorWipe(strip.Color(255, 25, 0), 0); //Orange
break;
}
}
// 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(0);
}
}