12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #include <RCSwitch.h>
- #include <Streaming.h>
- RCSwitch rcswitch = RCSwitch();
- void setup()
- {
- Serial.begin(9600);
- //timeout for Serial.find(),
- Serial.setTimeout(100);
-
- rcswitch.enableTransmit(4);
-
- Serial.println("ardvindo started");
- }
- void loop()
- {
- if(Serial.available() > 0)
- {
- // - 'i' info for identification
- // - 'e' enable / switch on
- // - 'd' disable / switch off
- char command = Serial.read();
-
- if(command == 'i')
- {
- Serial.println("ardvindo");
- }
- else if(command == 'e' || command == 'd')
- {
- //wait for space and family
- while(Serial.available() < 2)
- {
- delay(1);
- }
-
- Serial.read(); //space
- char family = Serial.read();
- int group = Serial.parseInt();
- int device = Serial.parseInt();
- if(command == 'e')
- {
- rcswitch.switchOn(family, group, device);
- }
- else
- {
- rcswitch.switchOff(family, group, device);
- }
-
- Serial << command << " " << family << " " << group << " " << device << "\n";
- }
-
- // strip all further chars until end of line
- Serial.find("\n");
- }
- }
|