Hi All
Is it possible to add more then one button switch? What I want to do is have 3 button switches and each have its own color assignment, I don't want it to blink or change between colors I want to just decide which snap to snap and have that color light up.
Thank You
JJ
Light-Up Angler Fish BANNED
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Light-Up Angler Fish BANNED
Sure. That's easy. Just define 3 button pins, and duplicate the code in setup() and loop() for each button. This should get you started. Change the colors to whatever you want
Code: Select all
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// 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
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 6, NEO_GRB + NEO_KHZ800);
const int button1Pin = 1; // the fin snap is connected to FLORA TX, the other half of the snap is conntected to GND
int button1State = 0; // variable for reading the snap status
const int button2Pin = 0; // the fin snap is connected to FLORA RX, the other half of the snap is conntected to GND
int button2State = 0; // variable for reading the snap status
const int button3Pin = 2; // the fin snap is connected to FLORA SDA, the other half of the snap is conntected to GND
int button3State = 0; // variable for reading the snap status
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT);
digitalWrite(button1Pin, HIGH);
pinMode(button2Pin, INPUT);
digitalWrite(button2Pin, HIGH);
pinMode(button3Pin, INPUT);
digitalWrite(button3Pin, HIGH);
}
void loop() {
// read the state of the pushbutton value:
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
button3State = digitalRead(button3Pin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button1State == LOW) {
// turn LED on:
strip.setPixelColor(0, strip.Color(200, 211, 254)); // color when snap is connected
strip.show();
}
else {
// change LED color
strip.setPixelColor(0, strip.Color(250, 0, 0)); // color when snap is disconnected
strip.show();
}
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button2State == LOW) {
// turn LED on:
strip.setPixelColor(0, strip.Color(200, 211, 254)); // color when snap is connected
strip.show();
}
else {
// change LED color
strip.setPixelColor(0, strip.Color(250, 0, 0)); // color when snap is disconnected
strip.show();
}
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (button3State == LOW) {
// turn LED on:
strip.setPixelColor(0, strip.Color(200, 211, 254)); // color when snap is connected
strip.show();
}
else {
// change LED color
strip.setPixelColor(0, strip.Color(250, 0, 0)); // color when snap is disconnected
strip.show();
}
delay(50);
}
- aaavacuumandsewingmedia
- Posts: 1
- Joined: Tue Jan 22, 2019 5:27 am
Re: Light-Up Angler Fish BANNED
Nice post, Sorry dear I don’t have any knowledge about this topic, I think you should discuss with an expert of BANNED.
monogram
monogram
Please be positive and constructive with your questions and comments.