Blynk write function

I am just going to make a simple gift for my friend in his coming birthday and it is a single speed fan. I think you got the point. I will set auto mode first then come to manual after.

Okay, if I was making a project like this Iā€™d do the followingā€¦

Controlsā€¦
Target temperature input (slider or step widget)
Master on/off switch
Auto/Manual switch
Manual on/off switch.

Logicā€¦
Use a timer to call a function every 5 seconds. Iā€™d call this function ā€œcompare()ā€

Global variables for:

  • master_on
  • target_temp
  • auto_flag
  • manual_on

The BLYNK_WRITE function for control widgets would do nothing except store the incoming parameters to the appropriate global variable and call the compare() function (this is just to make the control widgets more responsive, so you donā€™t have to wait up to 5 seconds before the control() function is called by the timer.

The compare() function would do the followingā€¦
Take a temperature reading and write the results to Blynk

Check if the master_on variable == true. If it is then proceed with the rest of the logic tests, if not then do nothing else.

If master_on == true and auto_flag == true then check if the actual temperature is higher than the target_temp value. If it is then turn the fan on, else turn the fan off.

If master_on == true and auto_flag == false then if manual_on == true then turn the fan on, else turn the fan off.

As you can see, all the logic comparisons are don in the timed function. The BLYNK_WRITE functions simply set the global variables.

Does this help?

Pete.

1 Like