Regela icon

SerialButton Arduino

Regela | PRO | 07/05/19 08:28:53 PM UTC | 0 ⭐ | 334 👁️ | Never ⏰ | []
C++ |

490 B

|

None

|

0 👍

/

0 👎

int triger = 1;
int button_pin = 12;
bool flag = false;
int trig(){
  triger=(triger+1)%2;
  return triger+1;
}
 
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(button_pin,INPUT_PULLUP);
}
 
void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(button_pin)==0){
    if(!flag){
      flag = true;      
      Serial.println(trig());
      delay(4000);
    }
  }else{
    flag = false;
  }
  delay(10);
  
}

Comments