//----the base and glove modules are wireless //----this code determines which signal comes first; from the base or from the glove //----the actuators are a red led (corresponds to the glove module) and a green led (corresponds to the base module) #include //import Ken Shirrif's IRremote library (for receiving and transmitting infrared signals) //in this case, we're receiving infrared signals const int RECV_PIN = 6; //make names for digital pins const int outpin = 2; const int safepin = 4; IRrecv irrecv(RECV_PIN); //create the receiver object decode_results results; //tell the RECV_PIN what to do (in this case, we're telling it to decode the results it receives) void setup() { //run through this before going to the loop pinMode(outpin, OUTPUT); //define pin modes pinMode(safepin, OUTPUT); irrecv.enableIRIn(); //begin the receiving process irrecv.blink13(true); //blink the LED during reception (helps with troubleshooting and gives visual feedback) } void loop() { //perform these commands over and over again if (irrecv.decode(&results)) { //attempt to receive a IR code //returns true if a code was received, false if not //when a code is received, information is stored in "results" if (results.decode_type == SONY) { //if the result is a Sony code, then... if (results.value == 16) { //if the actual IR code is 16 (from the glove module), then... int val= HIGH; //assign a value to a variable do{ //put it into a endless loop in which "outpin" will produce a HIGH output digitalWrite(outpin, val); //think of it like a bistable 555 timer, except that it's triggered by a Sony code "16" IR signal }while(val == HIGH); } else if (results.value == 3088) { //if the actual IR code is 3088 (from the base module), then... int gogo = HIGH; //put it into an endless loop in which "safepin" will produce a HIGH output do{ digitalWrite(safepin, gogo); }while(gogo == HIGH); } else { //if no code is received or a non-Sony code is received or a Sony code other than 16 or 3088 is received, then... digitalWrite(outpin, LOW); //produce a low output on the outpin digitalWrite(safepin, LOW); //produce a low output on the safepin } } irrecv.resume(); //receive the next value if any code was received } }