5
There is indeed a race condition in your code: if an interrupt fires
while you are reading one of the counters, you might read garbage. If it
fires between reading and resetting the counter, you loose one count.
The way to prevent the race is to block interrupts while the main thread
(everything that does not run in interrupt context) accesses the
counters. ...
5
ESP32. Dual core 240MHz, plus an extra XLP state machine. Cheap and easily available on eBay/Amazon/Ali Express etc. And with full Arduino support.
1
By best attempt to provide something of an answer.
You have said:
PT_WAIT_UNTIL(pt, millis() - lastTimeBlink > 1000);
That is not literally represented in your code, so I take your question to refer
to:
int dist2 = dist1.toInt();
...
PT_WAIT_UNTIL(pt, millis() - lastTimeBlink > (dist2 * 1710));
or a similar section.
When you execute this ...
1
The problem is that you check inside the two functions Sparkle and GreenYellow for another serial byte. Then when it's unequal, you move back to the while loop where you wait for the next serial byte, but I think you need to use the same one to decide to go to the correct function instead of waiting for a next serial byte.
Probably the easiest is to not read ...
answered Dec 16 '20 at 14:14
Michel Keijzers
11.8k77 gold badges2828 silver badges4949 bronze badges
1
esp32_technical_reference_manual_en.pdf
Page 620
As mentioned before, only an elevated process with PID of 0/1 can initiate a process switch. The new process
may have any PID from 0 ~ 7 after the process switch. The key for successful proactive process switching is that
Espressif Systems 620
Submit Documentation Feedback
ESP32 Technical Reference Manual V4.3
...
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
threads × 28arduino-uno × 8
programming × 7
interrupt × 4
sensors × 3
library × 3
serial × 2
arduino-mega × 2
led × 2
bluetooth × 2
esp8266 × 1
c++ × 1
communication × 1
shields × 1
timers × 1
ethernet × 1
analogread × 1
sketch × 1
esp32 × 1
web-server × 1
rgb-led × 1
robotics × 1
http × 1
hc-05 × 1
millis × 1