Arduino.ino 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <RCSwitch.h>
  2. #include <Streaming.h>
  3. RCSwitch rcswitch = RCSwitch();
  4. void setup()
  5. {
  6. Serial.begin(9600);
  7. //timeout for Serial.find(),
  8. Serial.setTimeout(100);
  9. rcswitch.enableTransmit(4);
  10. Serial.println("ardvindo started");
  11. }
  12. void loop()
  13. {
  14. if(Serial.available() > 0)
  15. {
  16. // - 'i' info for identification
  17. // - 'e' enable / switch on
  18. // - 'd' disable / switch off
  19. char command = Serial.read();
  20. if(command == 'i')
  21. {
  22. Serial.println("ardvindo");
  23. }
  24. else if(command == 'e' || command == 'd')
  25. {
  26. //wait for space and family
  27. while(Serial.available() < 2)
  28. {
  29. delay(1);
  30. }
  31. Serial.read(); //space
  32. char family = Serial.read();
  33. int group = Serial.parseInt();
  34. int device = Serial.parseInt();
  35. if(command == 'e')
  36. {
  37. rcswitch.switchOn(family, group, device);
  38. }
  39. else
  40. {
  41. rcswitch.switchOff(family, group, device);
  42. }
  43. Serial << command << " " << family << " " << group << " " << device << "\n";
  44. }
  45. // strip all further chars until end of line
  46. Serial.find("\n");
  47. }
  48. }