Advertisement
Guest User

butononoff

a guest
Oct 17th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1.  
  2. /*
  3. Button
  4.  
  5. Turns on and off a light emitting diode(LED) connected to digital
  6. pin 13, when pressing a pushbutton attached to pin 2.
  7.  
  8.  
  9. The circuit:
  10. * LED attached from pin 13 to ground
  11. * pushbutton attached to pin 2 from +5V
  12. * 10K resistor attached to pin 2 from ground
  13.  
  14. * Note: on most Arduinos there is already an LED on the board
  15. attached to pin 13.
  16.  
  17.  
  18. created 2005
  19. by DojoDave <http://www.0j0.org>
  20. modified 30 Aug 2011
  21. by Tom Igoe
  22.  
  23. This example code is in the public domain.
  24.  
  25. http://www.arduino.cc/en/Tutorial/Button
  26. */
  27.  
  28. // constants won't change. They're used here to
  29. // set pin numbers:
  30. const int buttonPin = 12; // the number of the pushbutton pin
  31. const int ledstandby = 10;
  32. const int ledsecurizare = 11;// the number of the LED pin
  33.  
  34. // variables will change:
  35. int buttonState = 0;
  36. int securizare = 0;// variable for reading the pushbutton status
  37.  
  38. void setup() {
  39. Serial.begin(9600);
  40. // initialize the LED pin as an output:
  41. pinMode(ledsecurizare, OUTPUT);
  42. pinMode(ledstandby, OUTPUT);
  43. // initialize the pushbutton pin as an input:
  44. pinMode(buttonPin, INPUT);
  45. }
  46.  
  47. void loop() {
  48.  
  49. // read the state of the pushbutton value:
  50. buttonState = digitalRead(buttonPin);
  51.  
  52. // check if the pushbutton is pressed.
  53. // if it is, the buttonState is HIGH:
  54. if (buttonState == 1 && securizare == 0) {
  55. delay(200);
  56. Serial.println("Sistem securizat!");
  57. securizare = 1;
  58. delay(5000);
  59.  
  60. }
  61. else if (buttonState == 1 && securizare == 1){
  62. delay(200);
  63. Serial.println("Securizare dezactivata!");
  64. securizare = 0;
  65. delay(1500);
  66.  
  67. }
  68.  
  69. if (securizare == 0) {
  70. digitalWrite(ledstandby, HIGH);
  71. delay(500);
  72. digitalWrite(ledstandby, LOW);
  73. delay(500);
  74. }
  75. else
  76. digitalWrite(ledsecurizare, HIGH);
  77. delay(150);
  78. digitalWrite(ledsecurizare, LOW);
  79. delay(150);
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement