const int ledPin = 13; // the number of the LED pin
boolean buttonState = LOW; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//pinMode(buttonPin, INPUT);
attachInterrupt(0,accendi,CHANGE);// 2=falling 3
}
void accendi(){
buttonState= HIGH;}
void loop(){
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
//delayMicroseconds(10000);
buttonState=LOW;}
}
non funziona rimane sempre acceso anzichè stare praticamente sempre spento come dovrebbe:
appena parte l'nterrupt rimane acceso anzichè spegnersi immediatamente o dopo un certo periodo impostato dal delay. anche se non metto il delay rimane comunque acceso.
funziona con l'esempio degli interrupt ma non così.immagino sia un errore banale ma non lo vedo...
hai tolto i commenti dalla riga //delayMicroseconds(10000); ?
fai così:
const int ledPin = 13; // the number of the LED pin
conts int buttonPin=2; // the number of the button pin
volatile int buttonState = LOW; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//pinMode(buttonPin, INPUT);
attachInterrupt(0,accendi,CHANGE);// 2=falling 3
}
void accendi(){
buttonState=! buttonState;}
void loop(){
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
delayMicroseconds(10000);
buttonState=LOW;}
else {
buttonState=LOW;}
}
tutto uguale. accendo scheda, creo il collegamento a 5v col pin 2 e il led 13 si accnde ma non si spegne finche non resetto o spengo, in entrambi gli sketch. ho èprovato anche con la buil 0020 ma uguale.
falling change rising low sempre uguale.. sto diventando pazzo
in ogni caso anche con una pullup non creerebbe un evento interrupt ciclico. poi analizzando l'uscita con un altro arduino non silevo dei low. rimane fisso high come se non vedesse il low che c'è dopo..
const int ledPin = 13; // the number of the LED pin
volatile int buttonState = LOW; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//pinMode(buttonPin, INPUT);
attachInterrupt(0,accendi,RISING);// 2=falling 3
}
void accendi(){
buttonState=! buttonState;}
void loop(){
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
delay(10);
buttonState=LOW;}
else {
buttonState=LOW;}
digitalWrite(ledPin, LOW);
}