Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // usiamo micros() al posto di millis solo per valutare con più precisione i tempi in gioco
- #define US_DEBOUNCE_TIME 300000
- #define interruptPin 2
- #define ledPin 13
- bool int_flag = false;
- unsigned long int_time;
- void pinChange() {
- // flag attivo, ma tempo ancora non trascorso
- if(!int_flag){
- int_flag = true;
- int_time = micros();
- }
- }
- void setup() {
- Serial.begin(115200);
- pinMode(ledPin, OUTPUT);
- pinMode(interruptPin, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(interruptPin), pinChange, CHANGE);
- }
- void loop() {
- // Se flag è attivo e sono passati US_DEBOUNCE_TIME eseguo il codice
- if( int_flag && ( micros() - int_time > US_DEBOUNCE_TIME )){
- int_flag = false;
- if( digitalRead(interruptPin) == HIGH ){
- //Serial.println("Livello Pin 2 HIGH");
- digitalWrite(ledPin, HIGH);
- }
- else{
- //Serial.println("Livello Pin 2 LOW");
- digitalWrite(ledPin, LOW);
- }
- //Serial.print("uS da interrupt + esecuzione codice: ");
- Serial.println(micros() - int_time);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement