I'm going to use an arduino as processor for my rfid car "keyless" system. Right now im stuck at the start/stop button. Im going to try to explain:
While one variable (or input) is high, and while the start button is high, i want another output high as long as the start button is. Second time the start button is pressed, another output is set low. Can someone please make me an example code for this?
byte lastState = HIGH;
void setup()
{
pinMode(2, INPUT); // outside Input from somewhere
pinMode(3, INPUT_PULLUP); // Start/stop button
pinMode(13, OUTPUT); // Indicator Led/Engine startup
}
void loop()
{
byte myButton = digitalRead(3); //read the button
if(digitalRead(2) == HIGH && myButton == LOW) // Button is seen as pressed when brought to ground "GND"
{
if(myButton != lastState) // if the button was pressed then released, proceed
{
digitalWrite(13, !digitalRead(13)); // toggle LED on/off
lastState = myButton; // update the lastState, stops the Led from constant toggling
}
}
else lastState = myButton; // when the button is unpressed, update the lastState again
}