Advertisement
safwan092

Untitled

Dec 1st, 2021
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include<SoftwareSerial.h>
  2. SoftwareSerial lora(3, 2);
  3.  
  4. long i = 0;
  5.  
  6. const int buttonPin = 8;
  7. int buttonState;
  8. int lastButtonState = LOW;
  9. unsigned long lastDebounceTime = 0;
  10. unsigned long debounceDelay = 50;
  11.  
  12. void setup() {
  13. pinMode(buttonPin, INPUT);
  14. Serial.begin(9600);
  15. lora.begin(9600);
  16. }
  17.  
  18. void loop() {
  19. int reading = digitalRead(buttonPin);
  20.  
  21. if (reading != lastButtonState) {
  22. lastDebounceTime = millis();
  23. }
  24.  
  25. if ((millis() - lastDebounceTime) > debounceDelay) {
  26. if (reading != buttonState) {
  27. buttonState = reading;
  28. if (buttonState == HIGH) {
  29. i++;
  30. lora.println(i);
  31. Serial.println(i);
  32. }
  33. }
  34. }
  35. lastButtonState = reading;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement