Closed Stephan35 closed 6 years ago
@Stephan35 How are you handling 1
and 0
by hand with the push button? I guess it is creating debounce. This link will explain more about this.
When you enter into the interrupt loop. First, you have to disable the interrupt. Once completed your actions reenable it.
I know about debounce , i already have same kind with another app. Normally adding delayMicroseconds(32000); solve it. In another way i also add this :
void Pin5Change(){
if (millis() - Gpio5_millis > 75){
delayMicroseconds(32000);
Serial.println("\n*** Pin5 Interrupt");
Gpio5_Checked = true;
Gpio5_millis = millis();
detachInterrupt(PIN_BP_GPIO5);
}
}
Gpio5_millis force to wait before another look of gpio state, but still not working As you can see , i also add , in a second way detachInterrupt, to wait end of gpio reading in loop.
The real problem of attachInterrupt is that is stopping all processus to do it . millis() still not work during , keep last value in fact.
Anyway, i do it another way, but i don't like it , removing attachinterrupt , and look at every loop the gpio state .... bad for me.
void loop() {
mc.loop();
long now = millis();
if (now - Scan_Gpio > 200 ){
Gpio4_S = digitalRead(PIN_BP_GPIO4);
Gpio5_S = digitalRead(PIN_BP_GPIO5);
Gpio14_S = digitalRead(PIN_BP_GPIO14);
if (Gpio4_S != Gpio4_LS ){
sendPin4(((Gpio4_S == HIGH) ? 1 : 0));
Gpio4_LS = Gpio4_S;
}
if (Gpio5_S != Gpio5_LS ){
sendPin5(((Gpio5_S == HIGH) ? 1 : 0));
Gpio5_LS = Gpio5_S;
}
if (Gpio14_S != Gpio14_LS ){
sendPin14(((Gpio14_S == HIGH) ? 1 : 0));
Gpio14_LS = Gpio14_S;
}
Scan_Gpio = now;
Serial.print(".");
}
/*
if (Gpio5_Checked) {
Gpio5_Checked = false;
sendPin5();
yield();
attachInterrupt(PIN_BP_GPIO5, (Pin5Change), CHANGE);
}
if (Gpio14_Checked) {
Gpio14_Checked = false;
sendPin14();
yield();
attachInterrupt(PIN_BP_GPIO14, (Pin14Change), CHANGE);
}
*/
//You can add your logic here.
if (now - lastRecu > 5000 ) {
lastRecu = now;
//sendRSSI();
sendLUX();
//send(SENSOR_LUXMETRE, analogRead(A0));
}
}
What do you think about it ?
@Stephan35 I hope the following line might resolve your issue. But I never tested ;) If it is not working please do not mind :)
void setup() {
...
..
..
attachInterrupt(PIN_BP_GPIO5, (Pin5Change), CHANGE);
attachInterrupt(PIN_BP_GPIO14, (Pin14Change), CHANGE); //digitalPinToInterrupt(x)
}
void Pin5Change(){
detachInterrupt(PIN_BP_GPIO5);
if(!Gpio5_Checked){
delayMicroseconds(32000);
Serial.println("\n*** Pin5 Interrupt");
Gpio5_Checked = true;
}
attachInterrupt(PIN_BP_GPIO5, (Pin5Change), CHANGE);
}
void Pin14Change(){
detachInterrupt(PIN_BP_GPIO14);
if(!Gpio14_Checked){
delayMicroseconds(32000);
Serial.println("\n*** Pin14 Interrupt");
Gpio14_Checked = true;
}
attachInterrupt(PIN_BP_GPIO14, (Pin14Change), CHANGE);
}
Seems submitter not interested anymore on this issue. I am closing this issue.
Hello, Inside sketch i used attachInterrupt . When i put GPIO5 or GPIO14 to 1 -> go immediatly to 1 When i release GPIO5 or GPIO14 to 0 -> nothing do
i was playing with these GPIO to understand whant append, then suddenly, all i done went at 1 time (so full of 1 and 0 at serial print)
Should i remove sendRSSI(); ?
Thanks