Thursday, December 2, 2021

POM... main dengan Infra Red dan LED...

 




Khamis, 2 Dis 2021... di saat Malaysia bakal dilanda Omicron tuh...

#define LedMerah 8
#define Led2 7
#define LedHijau 6
#define LedPutih 5
#define InfraRed1 12
#define InfraRed2 11
int Signal1 = 0;
int Signal2 = 0;

void setup() {
  // put your setup code here, to run once:

pinMode (LedMerah,OUTPUT);
pinMode (Led2,OUTPUT);
pinMode (LedHijau,OUTPUT);
pinMode (LedPutih,OUTPUT);
pinMode (InfraRed1,INPUT);
Serial.begin(9600);

}
void loop() 
{
Signal1 = digitalRead(InfraRed1);
Signal2 = digitalRead(InfraRed2);
// digitalWrite(LedMerah,HIGH);
//  delay(2000);
//  digitalWrite(LedMerah,LOW);
if(Signal1 == 0)

{ Serial.println("<---putih nyala--->");
  digitalWrite(LedPutih,LOW);
  delay(300);
  digitalWrite(LedPutih,HIGH);
  delay(200);
  digitalWrite(LedPutih,LOW);
 
}
else if(Signal2 == 0)
{
  Serial.println("<---putih & hijauh nyala--->");
  digitalWrite(LedPutih,HIGH);
  digitalWrite(LedHijau,HIGH);
  delay(200);
  digitalWrite(LedPutih,LOW);
  digitalWrite(LedHijau,LOW);
  delay(200);

}
if((Signal1 == 0)&&(Signal2 == 0))
{
  Serial.println("<---merah nyala--->");
digitalWrite(LedMerah,LOW);
  delay(300);
  digitalWrite(LedMerah,HIGH);
  delay(200);
  digitalWrite(LedMerah,LOW);
}
else
{ digitalWrite(LedHijau,LOW);
  delay(300);
  digitalWrite(LedHijau,HIGH);
  delay(200);
  digitalWrite(LedHijau,LOW);
}

}


No comments:

Post a Comment