Sparki has an Infrared LED. It is used to send information to other Sparkis like a remote control by rapidly blinking invisible infrared light.
Where code is an 8bit value. This can be a number from 0 to 255, or a character like ‘a’ or ‘D’. Sending a code like this will allow a Sparki nearby to receive it with the
Infrared Remote Receiver
SparkiDuino already has code examples for you to use:
File > Examples > Infrared LED
How It Works
Infrared remotes work by sending codes via flashing lights. These lights flash really fast; Sparki’s infrared LED flashes 38,000 times a second. By changing the amount of time between each flash, Sparki can send a burst that is meant to be a 1 or a 0, known as bits. Sparki sends these flashes until an entire code has been sent. Specifically, Sparki uses the NEC infrared code protocol.Using the Part
With the basic Sparki code in place, you can send infrared codes using this command:
1 |
sparki.sendIR(code); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/******************************************* Infrared LED Send Code example Sparki has an infrared LED. You can use it to communicate with other Sparkis and other devices that use infrared remote controls. Other Sparkis can receive the code using sparki.readIR(); This example has Sparki sending a code every second. The code increases each time by 1. When the code reaches 255, the biggest number it can send, it goes back to zero and starts all over again. ********************************************/ #include <Sparki.h> // include the sparki library void setup() { } int code = 0; void loop() { sparki.sendIR(code); code = code + 1; // increase code by 1 // set code back to 0 if it goes over 255 - the highest number sendIR can send if(code = 255){ code = 0; } delay(1000); // wait one second } |