Advertisement
RuiViana

EP_Transmissor

Jan 18th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. //HC-12 Momentary Button Send
  2. //Autor Tom Heylen tomtomheylen.com
  3. #include <SoftwareSerial.h>
  4. SoftwareSerial mySerial(2, 3);              //RX, TX
  5. int buttonPin  = 8;
  6. int buttonPin2 = 12;
  7. boolean onOff  = 0;
  8. boolean onOff2 = 0;
  9. //----------------------------
  10. void setup()
  11. {
  12.   pinMode(buttonPin,  INPUT);
  13.   pinMode(buttonPin2, INPUT);
  14.   mySerial.begin(9600);
  15. }
  16. //----------------------------
  17. void loop()
  18. {
  19.   int buttonState = digitalRead(buttonPin);     //read button state
  20.   int buttonState2 = digitalRead(buttonPin2);   //read button state
  21.   if (buttonState == 1)                         //if button is down
  22.   {
  23.     mySerial.println(1111);                     //send unique code to the receiver to turn on. In this case 1111
  24.     onOff = 1;                                  //set boolean to 1
  25.   }
  26.   if (buttonState == 0 && onOff == 1)           //Verifier to send off signal once
  27.   {
  28.     mySerial.println(0000);                     //send unique code to the receiver to turn off. In this case 0000
  29.   }
  30.   delay(20);                                    //delay little for better serial communication
  31.   if (buttonState2 == 1)                        //if button is down
  32.   {
  33.     mySerial.println(3333);                     //send unique code to the receiver to turn on. In this case 3333
  34.     onOff2 = 1;                                 //set boolean to 1
  35.   }
  36.   if (buttonState2 == 0 && onOff2 == 1)         //Verifier to send off signal once
  37.   {
  38.     mySerial.println(2222);                     //send unique code to the receiver to turn off. In this case 2222
  39.   }
  40.   delay(20);                                    //delay little for better serial communication
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement