-
Listening to client updates while displaying animations
06/20/2021 at 23:16 • 0 commentsWhen displaying animations on micro controller each frame is an instruction. Light these leds, now these ones, and so on.
So I was having the problem of how to make the animation loop keep running but still listen to new commands from the client.
After several attempts and reading the example programs more in depth I started to understand how the code works,The flow for receiving commands is:
- Client Connects
- Code reads what is at the ending of the client connection url
- Runs the code inside the respective url end
- Client Disconnects
server.avaible() will listen if there is a new call to the web server running on the ESP32 board. If there is one, will leave the loop of the animation and start again the general loop where it processes the requests.
In case the animation is too long we can make a checkpoint during the animation to abort the while loop if there's a new clientvoid swirl(){ uint8_t sweep[] = {1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40, 60, 60, 40, 30, 20, 15, 10, 8, 6, 4, 3, 2, 1}; while(!server.available()){ //run while there is no new calls for (uint8_t incr = 0; incr < 24; incr++) for (uint8_t x = 0; x < 16; x++) for (uint8_t y = 0; y < 9; y++) matrix.drawPixel(x, y, sweep[(x + y + incr) % 24]); //display leds delay(20); } }