01-05-2021, 07:44 PM
Hey everyone,
very cool projects! Just want to give a short explanation to the "configHandler" topic.
In your experiment the user can set a treshold with the edit field and send it to the arduino. The way you designed the .phyphox file, the treshold is transfered every analysis cycle. To actually use the last transfered treshold in your arduino sketch you have 2 options:
A) call: PhyphoxBLE:read(myFloat) to update the float variable myFloat with the newest treshold. The problem with this method is, that you dont have a strict time relation between new data has been transfered and is actually used in your sketch. You also have to call this function as often as possible to get the transfered data as soon as possible.
B) Instead of calling the read function many times you can write a function which is executed every time a new value is transfered to the arduino. Let say you want to blink your onboard led everytime you get data and update your float variable:
This function will do the variable update & blink job. Next step is to pass this function to the phyphox library so it gets executed after new data received.
With this method you dont have to call the read-function as often as possible. This is especially useful if you receive new data very rarely. Hope this helps a bit.
Cheers
Dominik
very cool projects! Just want to give a short explanation to the "configHandler" topic.
In your experiment the user can set a treshold with the edit field and send it to the arduino. The way you designed the .phyphox file, the treshold is transfered every analysis cycle. To actually use the last transfered treshold in your arduino sketch you have 2 options:
A) call: PhyphoxBLE:read(myFloat) to update the float variable myFloat with the newest treshold. The problem with this method is, that you dont have a strict time relation between new data has been transfered and is actually used in your sketch. You also have to call this function as often as possible to get the transfered data as soon as possible.
B) Instead of calling the read function many times you can write a function which is executed every time a new value is transfered to the arduino. Let say you want to blink your onboard led everytime you get data and update your float variable:
Code:
void example_function(){
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
[size=small] digitalWrite(LED_BUILTIN, LOW);[/size]
[size=small] [color=#000000][size=small][font=Tahoma, Verdana, Arial, sans-serif]PhyphoxBLE[/font][/size][/color][color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]:read(myFloat);[/font][/size][/color][/size]
}
This function will do the variable update & blink job. Next step is to pass this function to the phyphox library so it gets executed after new data received.
Code:
PhyphoxBLE::configHandler=&example_function; (this should be done in the setup block)
With this method you dont have to call the read-function as often as possible. This is especially useful if you receive new data very rarely. Hope this helps a bit.
Cheers
Dominik