Arduino.ino 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. }
  11. void loop()
  12. {
  13. if(Serial.available() > 0)
  14. {
  15. // - 'i' info for identification
  16. // - 'e' enable / switch on
  17. // - 'd' disable / switch off
  18. char command = Serial.read();
  19. if(command == 'i')
  20. {
  21. Serial.println("ardvindo");
  22. }
  23. else if(command == 'e' || command == 'd')
  24. {
  25. //wait for space and family
  26. while(Serial.available() < 2)
  27. {
  28. delay(1);
  29. }
  30. Serial.read(); //space
  31. char family = Serial.read();
  32. int group = Serial.parseInt();
  33. int device = Serial.parseInt();
  34. if(command == 'e')
  35. {
  36. rcswitch.switchOn(family, group, device);
  37. }
  38. else
  39. {
  40. rcswitch.switchOff(family, group, device);
  41. }
  42. Serial << command << " " << family << " " << group << " " << device << "\n";
  43. }
  44. // strip all further chars until end of line
  45. Serial.find("\n");
  46. }
  47. }