Advertisement
Speshal

433MHz Transceiver

Jan 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <RCSwitch.h>
  2.  
  3. RCSwitch mySwitch = RCSwitch();
  4. String inString = "";
  5.  
  6. void setup() {
  7. Serial.begin(9600);
  8. mySwitch.enableReceive(0);
  9. mySwitch.enableTransmit(6);
  10. pinMode(LED_BUILTIN, OUTPUT);
  11. Serial.println("Doomsday Machine ONLINE!...");
  12. }
  13.  
  14. void loop() {
  15. if (mySwitch.available()) {
  16. int value = mySwitch.getReceivedValue();
  17. if (value == 0) {
  18. Serial.println("Unknown encoding");
  19. } else {
  20. Serial.println( mySwitch.getReceivedValue() );
  21. digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
  22. blinker();
  23. }
  24. mySwitch.resetAvailable();
  25.  
  26. }
  27.  
  28. // Read serial input:
  29. while (Serial.available() > 0) {
  30. int inChar = Serial.read();
  31. if (isDigit(inChar)) {
  32. inString += (char)inChar;
  33. }
  34. if (inChar == '#') {
  35. long code = inString.toInt();
  36. mySwitch.send(code, 24);
  37. blinker();
  38. Serial.println(code);
  39. inString = "";
  40. }
  41. }
  42.  
  43. delay(10);
  44. }
  45.  
  46.  
  47. void blinker() {
  48. digitalWrite(LED_BUILTIN, HIGH);
  49. delay(30);
  50. digitalWrite(LED_BUILTIN, LOW);
  51. delay(30);
  52. digitalWrite(LED_BUILTIN, HIGH);
  53. delay(30);
  54. digitalWrite(LED_BUILTIN, LOW);
  55. delay(30);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement