schufti wrote:Hi,
most important thing for isr: has to be in IRAM!
void ICACHE_RAM_ATTR getcount(void)
in case it is not in IRAM there can be problem with caching (probably hw fault).
Lars Bo Wassini
Explore... Chat... Share...
Moderator: igrr
schufti wrote:Hi,
most important thing for isr: has to be in IRAM!
void ICACHE_RAM_ATTR getcount(void)
in case it is not in IRAM there can be problem with caching (probably hw fault).
const int pinButton = 0;
const int pinLed = 15;
const int pinFlowmeter = 5;
unsigned int totalCount = 500;
volatile unsigned int intCounter = 0;
bool buttonPressed = false;
int debugmeter = 0;
void setup() {
pinMode(pinLed, OUTPUT);
pinMode(pinButton, INPUT_PULLUP);
pinMode(pinFlowmeter, INPUT);
digitalWrite(pinLed, LOW);
Serial.begin(115200);
while (!Serial) {}
Serial.println();
Serial.println("Ready");
}
void loop() {
if (intCounter > ((totalCount/10) * (debugmeter+1))) {
debugmeter++;
Serial.println(String(debugmeter*10) + "%");
}
if (intCounter >= totalCount) {
detachInterrupt(digitalPinToInterrupt(pinFlowmeter));
Serial.println();
Serial.println("Complete: " + String(intCounter));
intCounter = 0;
buttonPressed = false;
digitalWrite(pinLed, LOW);
}
if (!buttonPressed && digitalRead(pinButton) == LOW) {
Serial.println();
pressButton();
}
delay(10);
}
void ICACHE_RAM_ATTR getcount() { // IMPORTANT!!! Have to be in RAM!
intCounter++;
}
void pressButton() {
if (!buttonPressed) { // prevent calling this several times
attachInterrupt(digitalPinToInterrupt(pinFlowmeter), getcount, FALLING);
buttonPressed = true;
digitalWrite(pinLed, HIGH);
Serial.println("Button pressed");
debugmeter = 0;
}
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]