Project 12: Arduino IR Remote-infrared communication
Main Ideas:
/*********
https://arduino4everyones.blogspot.com/ *********/ #include <IRremote.h> const int RECV_PIN = 7; IRrecv irrecv(RECV_PIN); decode_results results; unsigned long key_value = 0; int onoff =
15; // control the blinking int led_green = 11; // the red LED is connected to
Pin 11 of the Arduino int led_yellow = 12; // the yellow LED is connected
to Pin 12 of the Arduino int led_red = 13; // the green LED is connected to
Pin 13 of the Arduino int led_white = 10; // the green LED is connected to
Pin 13 of the Arduino void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); //
irrecv.blink13(true); // set up
all the LEDs as OUTPUT
pinMode(led_red, OUTPUT);
pinMode(led_yellow, OUTPUT); pinMode(led_green, OUTPUT);
//blinking(); } void loop() { if
(irrecv.decode(&results)) { if
(results.value == 0XFFFFFFFF)
results.value = key_value; switch
(results.value) { case
0xFFA25D:
Serial.println("CH-"); //
turn the green LED on and the other LEDs off
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_green, HIGH );
digitalWrite(led_white, LOW ); break; case
0xFF629D: Serial.println("CH"); //
turn the yellow LED on and the other LEDs off
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW ); break; case 0xFFE21D:
Serial.println("CH+"); //
turn the red LED on and the other LEDs off
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, LOW);
digitalWrite(led_green, LOW); break; case
0xFF22DD:
Serial.println("|<<"); //
turn the red LED on and the other LEDs off
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW ); break; case 0xFF02FD:
Serial.println(">>|"); //
turn the red LED on and the other LEDs off
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, HIGH);
digitalWrite(led_white, LOW ); break
; case
0xFFC23D:
Serial.println(">|"); //
turn the red LED on and the other LEDs off
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, HIGH); break
; case 0xFFE01F:
Serial.println("-");
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, HIGH );
digitalWrite(led_white, HIGH ); break
; case
0xFFA857:
Serial.println("+"); break
; case
0xFF906F:
Serial.println("EQ"); break
; case
0xFF6897:
Serial.println("0"); //
turn the red LED on and the other LEDs off
digitalWrite(led_red, LOW); digitalWrite(led_yellow, LOW);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW ); break
; case
0xFF9867:
Serial.println("100+");
blinking(); break
; case
0xFFB04F:
Serial.println("200+"); break
; case
0xFF30CF:
Serial.println("1"); break
; case
0xFF18E7:
Serial.println("2"); break
; case
0xFF7A85:
Serial.println("3"); break
; case
0xFF10EF:
Serial.println("4"); break
; case
0xFF38C7:
Serial.println("5"); break
; case
0xFF5AA5:
Serial.println("6"); break
; case
0xFF42BD:
Serial.println("7"); break
; case 0xFF4AB5:
Serial.println("8"); break
; case
0xFF52AD:
Serial.println("9"); break
; } key_value
= results.value;
irrecv.resume();
delay(100); } } void blinking() { int looponoff = 0; // save the time that we
started moveback while
(looponoff < onoff) // stay in this loop until timeToTrunRight5CM (
seconds) has elapsed { looponoff
= looponoff + 1; // turn
the green LED on and the other LEDs off digitalWrite(led_red,
LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_green, LOW );
digitalWrite(led_white, HIGH );
delay(100); // wait 2 seconds // turn
the green LED on and the other LEDs off
digitalWrite(led_red, LOW); digitalWrite(led_yellow,
LOW);
digitalWrite(led_green, HIGH );
digitalWrite(led_white, LOW );
delay(100); // wait 2 seconds // turn
the yellow LED on and the other LEDs off
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW );
delay(100); // wait 0.5 second // turn
the red LED on and the other LEDs off
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, LOW);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW );
delay(100); // wait 2 seconds } // turn off
all EDs off
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_green, LOW);
digitalWrite(led_white, LOW ); } |
No comments:
Post a Comment