Advertisement
RuiViana

Usa RC de RF

Dec 6th, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <RCSwitch.h>
  2. RCSwitch mySwitch = RCSwitch();
  3. unsigned long Received;
  4. #define LED1 3 // LED1 na porta 3
  5. #define LED2 4 // LED1 na porta 4
  6. //----------------------------------------------------------
  7. void setup()
  8. {
  9. Serial.begin(9600);
  10. mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
  11. }
  12. //----------------------------------------------------------
  13. void Aciona()
  14. {
  15. switch (Received)
  16. {
  17. case 5633795:
  18. {
  19. digitalWrite(LED1 , 1);
  20. break;
  21. }
  22. case 5633804:
  23. {
  24. digitalWrite(LED2 , 1);
  25. break;
  26. }
  27. }
  28. }
  29. //----------------------------------------------------------
  30. void loop()
  31. {
  32. if (mySwitch.available())
  33. {
  34. int value = mySwitch.getReceivedValue();
  35. if (value == 0)
  36. {
  37. Serial.print("Unknown encoding");
  38. }
  39. else
  40. {
  41. Serial.print("Received ");
  42. Serial.print( mySwitch.getReceivedValue() );
  43. Received =( mySwitch.getReceivedValue() );
  44. Aciona();
  45. Serial.print(" / ");
  46. Serial.print( mySwitch.getReceivedBitlength() );
  47. Serial.print("bit ");
  48. Serial.print("Protocol: ");
  49. Serial.println( mySwitch.getReceivedProtocol() );
  50. }
  51. mySwitch.resetAvailable();
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement