Send data from phone to arduino to regulate a led brightness

Yes, it should work, have you tried with the App?

That's the sketch I used to test it and it gave me that list error. It's probably a silly one, now @ABG is checking the App sketch

These are draggable replacement Click events that will prevent the Select List Item error messages ...

P.S. These blocks can be dragged directly into your Blocks Editor workspace.

I found a bug in your blocks. In the clock component, remove the block that sets Sensor_Data to "epty list".

This will protect the program but still won't work because its list is still empty, reset by the clock.

1 Like

This way, even with an incorrect reading, will leave the data from the previous reading.

Okay, I will try all of what you two told me tomorrow, thank you!

Okay, I've done this and it works just fine! Thanks! Should I add also what @ABG suggested or are these 2 different approaches to the problem?

Plus, I've just noticed a problem that comes up with the excessive amount of Serial.readStringUntil(). I tried controlling the leds by fluidly sliding the thumb on the slider and I experienced a massive delay in the response, and once I disabled the temperature and humidity Serial.readStringUntil() , it started working again. Is there any way I can correct this? Perhaps I could divide the two blocks but I don't know how since the condition is always if(Serial.available())

bluetooth_automation.txt (7.9 KB)

You can add these security features. In case the list breaks down somehow.

You have a lot of delays of 500ms in the program.
The best program is one that works without "delay()";

1 Like

Okay, I did both and it works well. I'm now trying to fix the issue I've mentioned in the previous message but with no result.

Yes, it's true, but aren't those delays supposed to trigger only when the program enters the switch? Should I create a variable that determines which screen I want to open and do operations there so that they don't happen at the same time? Because basically temperature&humidity and leds are on separate screens. Is it convenient?

No.

Switching Screens breaks your BlueTooth connection.

Instead of Screens, add Vertical Arrangements to Screen1, only one of them Visible at a time.

The Designer has Copy (ctrl-C) and Paste (Ctrl-V) to help you consolidate components from Screen to Screen.

Regarding the problem of identifying which datum has been sent, you could send them separately to AI2 with tags attached, similar to how JSON tags its values in a JSON object:
T:98.6,H:50

JSON adds a {} wrapper to announce that it is an object.

JSON is perfect for cases where you might be sending only one or the other datums:
T:98.6
T:98.6,H::50
H:50

  • To parse this, start by splitting at ',', to get individual readings.
  • Traverse the list with a for each loop.
  • For each reading, test if it has a : (text Contains)
    • If the reading has a : then
      * split the reading at : into a temp list
      * Use item 1 to decide which Label to assign item 2 into.
      (You could init a global table of (tag,Label Component) pairs for this, and use the lookup in pairs list block to turn tag into Label component, then use the set Any Label.Text block for the display.)

Oh no I didn't mean that. Now I only use vertical arrangements. I meant that logically I would want them to be on different screens.

So far the sending data part from arduino to AI2 has worked. It's the opposite that's been problematic. How can I have more serial.read() from arduino without it causing delays in response etc?

This is the problem now

Any help? Anyone?