this is my first arduino project, it's my first electronics project, it's my first led project. everything i know has been pieced together from forums and instructables, so bear with me please. i'm determined to learn.
i am helping a friend with his sculpture project. i have RGB led's that i want to put in one part of the sculpture, and have arcade-style buttons that viewers will be able to push to light up the led's. three buttons, one for each color, so that a variety of colors can be created.
so let's say i've got 5 led's wired in parallel, with one button to trigger each RGB. so when none of the buttons are pushed down, there are no lights. i modified the code of the "button" example that comes with the arduino software to have three buttons instead of one.
but it doesn't work. sometimes lights will go on randomly, or when i hold down one button for more than a second all the lights will turn on. does it look like there's a big problem with the code? or have i wired it all wrong? or is there a bigger problem that i don't even know about?
again i'm a beginner, any advice, or links to tutorials, or even a book i could read, would be helpful. the code i am using is below:
// set pin numbers:
const int blackbuttonPin = 2; // the number of the pushbutton pin
const int blueledPin = 13; // the number of the LED pin
const int yellowbuttonPin = 3;
const int greenledPin = 12;
const int redbuttonPin = 4;
const int redledPin = 11;
// variables will change:
int blackbuttonState = 0; // variable for reading the pushbutton status
int yellowbuttonState = 0;
int redbuttonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(blueledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(blackbuttonPin, INPUT);
pinMode(yellowbuttonPin, INPUT);
pinMode(redbuttonPin, INPUT);
pinMode(redledPin, OUTPUT);
pinMode(greenledPin, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
blackbuttonState = digitalRead(blackbuttonPin);
yellowbuttonState = digitalRead(yellowbuttonPin);
redbuttonState = digitalRead(redbuttonPin);
// check if the pushbutton is pressed.
// if it is, the blackbuttonState is HIGH:
if (blackbuttonState == HIGH) {
// turn LED on:
digitalWrite(blueledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(blueledPin, LOW);
}
if (yellowbuttonState == HIGH) {
digitalWrite(greenledPin, HIGH);
}
else {
digitalWrite(greenledPin, LOW);
}
if (redbuttonState == HIGH) {
digitalWrite(redledPin, HIGH);
}
else {
digitalWrite (redledPin, LOW);
}
}