Surya_from_1627

IOT6

Oct 4th, 2026
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. int ledpin=11; //definition digital 11 pins as pin to control the LED
  2. int btnpin=2; //Set the digital 2 to button interface
  3. volatile int state = LOW; // Defined output status LED Interface
  4. void setup()
  5. {
  6. pinMode(ledpin,OUTPUT);
  7. //Set digital 11 port mode, the OUTPUT for the output
  8. pinMode(btnpin,INPUT);
  9. //Set digital 2 port mode, the INPUT for the input
  10. }
  11. void loop()
  12. {
  13. if(digitalRead(btnpin)==LOW) //Detection button interface to
  14. low
  15. {
  16. delay(10); //Delay 10ms for the elimination of key
  17. leading-edge jitter
  18. if(digitalRead(btnpin)==LOW) //Confirm button is pressed
  19. {
  20. while(digitalRead(btnpin)==LOW);
  21. //Wait for key interfaces to high
  22. delay(10);
  23. //delay 10ms for the elimination of key trailing-edge jitter
  24. while(digitalRead(btnpin)==LOW);//Confirm button release
  25. state = !state;
  26. //Negate operation, each time you run the program here,
  27. state the HIGH becomes LOW, or the state becomes the
  28. LOW HIGH.
  29. digitalWrite(ledpin,state);
  30. //Output control status LED, ON or OFF
  31. }
  32. }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment