Instantly share code, notes, and snippets.

Embed
What would you like to do?
int btY = 10;
int btR = 13;
int ledY = 7;
int ledR = 8;
int btYState = 0;
int btRState = 0;
int btYCounter = 0;
int btYCounter_old = 0;
int btRCounter = 0;
int btRCounter_old = 0;
long lastChange1;
int blinkRate1 = 200;
boolean ledState1;
long lastChange2;
int blinkRate2 = 200;
boolean ledState2;
void setup()
{
Serial.begin(9600);
pinMode(ledR, OUTPUT);
pinMode(ledY, OUTPUT);
pinMode(btR, INPUT);
pinMode(btY, INPUT);
}
void loop()
{
btYCounter = digitalRead(btY);
btRCounter = digitalRead(btR);
if((btYCounter == HIGH) && (btYCounter_old == LOW))
{
digitalWrite(ledY, HIGH);
digitalWrite(ledR, LOW);
Serial.println("11");
Serial.println(btYCounter);
}
if((btRCounter == HIGH) && (btRCounter_old == LOW))
{
digitalWrite(ledR, HIGH);
digitalWrite(ledY, LOW);
Serial.println("22");
Serial.println(btRCounter);
}
btRCounter_old = btRCounter;
btYCounter_old = btYCounter;
if(btRCounter == HIGH)
{
if(millis()-lastChange1 > blinkRate1)
{
ledState1 = !ledState1;
lastChange1 = millis();
Serial.println("222");
}
}
if(btYCounter == HIGH)
{
if(millis()-lastChange2 > blinkRate2)
{
ledState2 = !ledState2;
lastChange2 = millis();
Serial.println("111");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment