coolwolf / 25/07/2014
Arduino ile tetiklemeli 3’lü led yakma programı:
int LED1=2;
int LED2=3;
int LED3=4;
int sonLED=0;
int okuIN=8;
unsigned long sonZAMAN=0;
void setup()
{
Serial.begin(9600);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(okuIN,INPUT);
sonZAMAN=millis();
}
void loop()
{
int dugme=digitalRead(okuIN);
if(dugme==HIGH && millis()-sonZAMAN>300)
{
Serial.print("sonzaman:");
Serial.print(sonZAMAN);
Serial.print(" millis:");
Serial.println(millis());
Kaydir();
sonZAMAN=millis();
}
}
void Kaydir()
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
if(sonLED==0 || sonLED==3)
{
digitalWrite(LED1,HIGH);
sonLED=1;
} else if(sonLED==1)
{
digitalWrite(LED2,HIGH);
sonLED=2;
}else if(sonLED==2)
{
digitalWrite(LED3,HIGH);
sonLED=3;
}
}