Hi all,
This should be something that's really simple to do but I'm not sure how to do it.
On my breadboard I have a multi coloured LED which displays in red and green. This LED is plugged in to two of the digital pins and ground.
I'm using an RFID reader which operates a couple of motors so when the RFID tag is placed over the reader the motors run and the LED glows red or green depending on which direction the motors move.
What I want to do is the same process as above but instead of using the RFID reader the push button is used. So there would be two ways of operating the motors, the push button and the RFID reader.
I've read a number of push button tutorials but so far I've not found anything that's helping me with this.
Anyone got any ideas how to connect up the push button? Or any links to a suitable tutorial would be good.
I've attached an image of what I've got so far.
This is the code I'm using to test it
int redPin = 2;
int greenPin = 8;
//int bluePin = 8;
int button = 1; // button pin
void setup()
{
Serial.begin(115200);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(button, INPUT); // button on pin 1
}
void loop()
{
int state = digitalRead(button);
Serial.print(state);
/* check if button is pressed */
if (state == HIGH) {
Serial.print("Green");
setColor(0, 255, 0); // Green
delay(1000);
Serial.print("Red");
setColor(255, 0, 0); // Red
delay(1000);
} else {
Serial.print("state is LOW");
}
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, 255-red);
analogWrite(greenPin, 255-green);
// analogWrite(bluePin, 255-blue);
}
Cheers,
CaptainChainsaw