I need to know when the user holds the mode button to put the device into AP mode.
According to the docs there is a nice feature of System Events. Which they give an example:
void handle_all_the_events(system_event_t event, int param)
{
Serial.printlnf("got event %d with value %d", event, param);
}
void setup()
{
// listen for Wi-Fi Listen events and Firmware Update events
System.on(wifi_listen+firmware_update, handle_all_the_events);
}
Yet, when I tried this i am unable to perform a if statement on the param value, so I changed it to this to see whats going on and I cannot make any sense of what the problem is. Here is my code.
void handle_AP_events(system_event_t event, int param)
{
int x = param;
Serial.printlnf("Got event %d with value %d", event, param);
Serial.printlnf("Repeat:%d", x);
if(x == 2)
{
Serial.printlnf("AP Mode Started");
}
else if(x == 4)
{
Serial.printlnf("AP Mode Running");
}
else if(x == 8)
{
Serial.printlnf("AP Mode Ended");
}
}
Here is the output of the terminal, Why is X changing values over and over ?
Got event 129 with value 2
Repeat:0
Got event 129 with value 4
Repeat:1100
Got event 129 with value 4
Repeat:2200
Got event 129 with value 4
Repeat:3300
Got event 129 with value 4
Repeat:4400
Got event 129 with value 4
Repeat:5500
Got event 129 with value 4
Repeat:6600
Got event 129 with value 4
Repeat:7700
Got event 129 with value 4
Repeat:8800
Got event 129 with value 4
Repeat:9900
Got event 129 with value 4
Repeat:11000