Belajar mikrokontroler dengan arduino menggunakan perulangan FOR
Contoh :
int lampu0 = 0 ;
int lampu1 = 2 ;
int lampu2 = 4 ;
void setup() {
pinMode(lampu0, OUTPUT);
pinMode(lampu1, OUTPUT);
pinMode(lampu2, OUTPUT);
}
void loop()
{
digitalWrite(lampu0, HIGH);
delay(1000);
digitalWrite(lampu0, LOW);
delay(1000);
for (int i=0; i<5; i++)
{
digitalWrite(lampu1, HIGH);
delay(1000);
digitalWrite(lampu1, LOW);
delay(1000);
}
digitalWrite(lampu2, HIGH);
delay(1000);
digitalWrite(lampu2, LOW);
delay(1000);
for (int i=0; i < 3; i++)
{
digitalWrite(lampu1, HIGH);
delay(1000);
digitalWrite(lampu1, LOW);
delay(1000);
}
}
Contoh :
int lampu0 = 0 ;
int lampu1 = 2 ;
int lampu2 = 4 ;
void setup() {
pinMode(lampu0, OUTPUT);
pinMode(lampu1, OUTPUT);
pinMode(lampu2, OUTPUT);
}
void loop()
{
digitalWrite(lampu0, HIGH);
delay(1000);
digitalWrite(lampu0, LOW);
delay(1000);
for (int i=0; i<5; i++)
{
digitalWrite(lampu1, HIGH);
delay(1000);
digitalWrite(lampu1, LOW);
delay(1000);
}
digitalWrite(lampu2, HIGH);
delay(1000);
digitalWrite(lampu2, LOW);
delay(1000);
for (int i=0; i < 3; i++)
{
digitalWrite(lampu1, HIGH);
delay(1000);
digitalWrite(lampu1, LOW);
delay(1000);
}
}
0 komentar:
Posting Komentar