Attiny84 Gestion des Interruptions

Bonjour a tous.
Je souhaite construire un pluviometre avec un attiny84.
J'aurais donc besoin a partir d'une interruptiin externe de reveiller l'attiny84.
Dans un premier stade j'essaye de de tester l'interruption sur une pin.
J'ai donc fait un premier sketch pour vérifier que j'ai bien identifié la pin connectée au bouton poussoir puis ground, et bien repéte le pin led.

Ce programme fonctionne j'ai bien un changemen,t d'etat quand j'aoouie sur le bouton

code ci après:`

// test du bouton et de la led

const byte ledPin = 3;
const byte interruptPin = 0;
volatile byte state = LOW;

void setup() {
Serial.begin(4800);
delay(1000);
Serial.println("Attiny Test Interrupt");
pinMode(ledPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
delay(3000);
digitalWrite(ledPin, LOW);

pinMode(interruptPin, INPUT_PULLUP);
}

void loop() {

Serial.print("interruptPin: ");
delay(100);
Serial.println(digitalRead(interruptPin));
}
/* Sortie Moniteur Série

20:00:10.445 -> interruptPin: 1
20:00:10.600 -> interruptPin: 1
20:00:10.712 -> interruptPin: 1
20:00:10.858 -> interruptPin: 1
20:00:11.011 -> interruptPin: 1
20:00:11.123 -> interruptPin: 0
20:00:11.266 -> interruptPin: 1
20:00:11.391 -> interruptPin: 0
20:00:11.518 -> interruptPin: 1
20:00:11.678 -> interruptPin: 1
20:00:11.817 -> interruptPin: 0
20:00:11.939 -> interruptPin: 1
20:00:12.065 -> interruptPin: 0
20:00:12.222 -> interruptPin: 1
20:00:12.350 -> interruptPin: 1
20:00:12.522 -> interruptPin: 0
20:00:12.635 -> interruptPin: 1
20:00:12.757 -> interruptPin: 1

*/

J'essaye donc de passer à l'étape suivante en detection une interruption externe:

Code ci après:`

``

const byte ledPin = 3;
const byte interruptPin = 0;
volatile byte state = LOW;

void setup() {
Serial.begin (4800);
delay(1000);
Serial.println ("Attiny Test Interrupt");
pinMode(ledPin, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite (ledPin, HIGH);
delay (3000);
digitalWrite (ledPin,LOW);

pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
Serial.print ("ledState: ");
Serial.println (state);
digitalWrite(ledPin, state);
}

void blink() {
Serial.print ("Interrupt ");
state = !state;
}

/* Sortie Console
20:08:39.596 -> ledState: 0
20:08:39.626 -> ledState: 0
20:08:39.657 -> ledState: 0
20:08:39.689 -> ledState: 0
20:08:39.721 -> ledState: 0
20:08:39.753 -> ledState: 0
20:08:39.753 -> ledState: 0
*/`

Citation

et là je ne detecte pas l'appui sur le bouton.

je dois donc mal utiliser la fonction d'interruption.

J'utilise l'AttinyCore.

Merci de votre aide et suggestions pour avancer sur mon projet

Malheureusement comme tu ne respect pas les recommandations du post sur les bonnes pratiques pour poster. Ton code est illisible.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.