aboutsummaryrefslogtreecommitdiff
path: root/doc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino
diff options
context:
space:
mode:
Diffstat (limited to 'doc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino')
-rwxr-xr-xdoc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino35
1 files changed, 35 insertions, 0 deletions
diff --git a/doc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino b/doc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino
new file mode 100755
index 0000000..59560e7
--- /dev/null
+++ b/doc/Lesson 3 Infrared Remote Control Car/infrared_Blink/infrared_Blink.ino
@@ -0,0 +1,35 @@
+//www.elegoo.com
+//2016.09.12
+
+#include <IRremote.h>//Infrared Library
+int receiverpin = 12;//Infrared signal receiving pin
+int LED=13; //define LED pin
+volatile int state = LOW; //define default input mode
+unsigned long RED;
+#define L 16738455
+IRrecv irrecv(receiverpin);//initialization
+decode_results results;//Define structure type
+void setup() {
+pinMode(LED, OUTPUT); //initialize LED as an output
+Serial.begin(9600); // debug output at 9600 baud
+ irrecv.enableIRIn();// Start receiving
+}
+void stateChange()
+{
+ state = !state;
+ digitalWrite(LED, state);
+}
+void loop() {
+if (irrecv.decode(&results))
+ {
+ RED=results.value;
+ Serial.println(RED);
+ irrecv.resume(); // Receive the next value
+ delay(150);
+ if(RED==L)
+ {
+ stateChange();
+ }
+ }
+ }
+