This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Double acoustic stopwatch and speed of sound
#5
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:

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
Reply


Messages In This Thread
RE: Double acoustic stopwatch and speed of sound - by Dominik Dorsel - 01-05-2021, 07:44 PM

Forum Jump: