// This #include statement was automatically added by the Particle IDE. #include "IRremote.h" unsigned int S_pwr[68]={4600,4350,700,1550,650,1550,650,1600,650,450,650,450,650,450,650,450,700,400,700,1550,650,1550,650,1600,650,450,650,450,650,450,700,450,650,450,650,450,650,1550,700,450,650,450,650,450,650,450,650,450,700,400,650,1600,650,450,650,1550,650,1600,650,1550,650,1550,700,1550,650,1550,650}; unsigned int S_pup[68]={4600,4350,700,1500,700,1500,700,1550,700,450,650,400,700,450,650,450,700,400,700,1500,700,1550,650,1550,700,450,650,450,700,400,700,400,700,400,700,400,700,1550,700,400,700,400,700,1550,650,450,700,400,700,400,700,1550,650,450,650,1600,650,1550,650,450,700,1500,700,1500,700,1550,650}; unsigned int S_pdown[68]={4650,4300,700,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,650,450,650,1550,700,1500,700,1550,700,400,700,400,700,400,700,450,700,400,700,400,700,400,700,450,650,450,650,1550,700,400,700,450,650,400,700,1550,700,1500,700,1550,700,1500,700,400,700,1550,650,1550,700,1500,700}; IRsend irsend(D1); int light1 = D7; int sw = D4; int relay1 = D6; int force_cmd = 0; int prevpull = 0; int prevpush = 0; int prevthrow = 0; void setup() { pinMode(light1, OUTPUT); pinMode(relay1, OUTPUT); pinMode(sw, INPUT); Spark.function("jedi",Jedi); digitalWrite(light1, LOW); digitalWrite(relay1, LOW); digitalWrite(sw, LOW); } void loop() { } int Jedi(String force_cmd) { if (force_cmd == "pull" && prevpull == 0) { digitalWrite(relay1, HIGH); prevpull = 1; force_cmd = 0; delay(1000); } if (force_cmd == "pull" && prevpull == 1) { digitalWrite(relay1, LOW); prevpull = 0; force_cmd = 0; delay(1000); } if (force_cmd == "push" && prevpush == 0) { digitalWrite(light1, HIGH); irsend.sendRaw(S_pwr, 68, 38); digitalWrite(light1, LOW); force_cmd = 0; delay(500); } if (force_cmd == "push" && prevpush == 0) { digitalWrite(light1, HIGH); irsend.sendRaw(S_pwr, 68, 38); digitalWrite(light1, LOW); force_cmd = 0; delay(500); } if (force_cmd == "throw" && prevthrow == 0) { digitalWrite(light1, HIGH); irsend.sendRaw(S_pdown, 68, 38); digitalWrite(light1, LOW); prevpull = 1; force_cmd = 0; delay(1000); } if (force_cmd == "throw" && prevthrow == 1) { digitalWrite(light1, HIGH); irsend.sendRaw(S_pdown, 68, 38); digitalWrite(light1, LOW); prevpull = 0; force_cmd = 0; delay(1000); } if ((digitalRead(sw) == HIGH) && (prevpull = 1)) { digitalWrite(light1, HIGH); digitalWrite(relay1, HIGH); prevpull = 1; force_cmd = 0; delay(1000); } if ((digitalRead(sw) == HIGH) && (prevpull = 0)) { digitalWrite(light1, LOW); digitalWrite(relay1, LOW); prevpull = 0; force_cmd = 0; delay(1000); } }