Advertisement
Regela

SerialButton Arduino

Jul 5th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. int triger = 1;
  2. int button_pin = 12;
  3. bool flag = false;
  4. int trig(){
  5.   triger=(triger+1)%2;
  6.   return triger+1;
  7. }
  8.  
  9. void setup() {
  10.   // put your setup code here, to run once:
  11.   Serial.begin(9600);
  12.   pinMode(button_pin,INPUT_PULLUP);
  13. }
  14.  
  15. void loop() {
  16.   // put your main code here, to run repeatedly:
  17.   if(digitalRead(button_pin)==0){
  18.     if(!flag){
  19.       flag = true;      
  20.       Serial.println(trig());
  21.       delay(4000);
  22.     }
  23.   }else{
  24.     flag = false;
  25.   }
  26.   delay(10);
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement