Bluetooth Connection in other screens

oh sorry I didn't know the difference, hold on i'll change it

Please read through
http://ai2.appinventor.mit.edu/reference/blocks/text.html

Take the Grand Tour.

It's worth your while.

1 Like

So I changed the code and the alert layout does pop up but it pops up as soon as it connected to the bluetooth, I didn't even click on a button...

What's in global message?
Did you fail to reset it after the previous alarm?

1 Like

Well the message should only be received once the arduino button is clicked but I haven't clicked anything and reset the previous alarm? How to I reset it? :sweat_smile:

for testing purposes I tried to just play with two buttons where each button respectively say "ROOM 1, EMERGENCY CALL!!" and "ROOM 2, EMERGENCY CALL!!". Both texts are shown though when the alert layout pops up as soon as the bluetooth connects

blocks

1 Like

Do I add it at the bottom of the loop?

You add it at the place that's after all the work you do to respond to its contents, before the next BT incoming message arrives.

1 Like

I added it to the button that stop all of it and the procedure that contains all the things that should happen once it reads the contains of "!!" but still the same thing... I'm not sure how it is reading both of the arduino button's emergency texts without me even clicking the button

Where is the place that you set the RoomAlertText.Text to blank?

1 Like

As of right now here are my alert blocks:

Another thing to consider:

Your Arduino code is set to delay 50 ms between messages.
How many ms does your Clock Timer wait before checking the next incoming message?
Unless it's faster (less ms) than the Arduino, those extra messages will pile up in the AI2 BT input buffer, and keep coming, until you have stopped the Arduino from sending them and until you have cleared all the input messages.
Here's what might happen, courtesy of Lucy and Ethel ...

1 Like

Okay so delay the message, i'll delay the message. hopefully it'll work

increasing the delay value just delays the emrgency txts sent to the alerttxt label, the alert layour still pops up immediately after connected to the bluetooth....

You have two possibilities ...

  • Your Arduino is still sending alerts
  • Your app is still responding to old alerts.

I notice in your Arduino code that you might be skipping incoming bytes with value 13 in this code sequence, expecting alternate lights and alerts values, instead of single values that need to be examined to see if they are a light or an alert value.

 
  if(Serial2.available()){
  
    //Room1 Lights(Apps)
    lights = Serial2.read();
    if(lights == 1) digitalWrite(LedR1, HIGH);
    if(lights == 2) digitalWrite(LedR1, LOW);
    if(lights == 3) digitalWrite(LedR2, HIGH);
    if(lights == 4) digitalWrite(LedR2, LOW);
    if(lights == 5) digitalWrite(LedR3, HIGH);
    if(lights == 6) digitalWrite(LedR3, LOW);
    if(lights == 7) digitalWrite(LedR4, HIGH);
    if(lights == 8) digitalWrite(LedR4, LOW);
    if(lights == 11) digitalWrite(LedBath, HIGH);
    if(lights == 12) digitalWrite(LedBath, LOW);
  }

  if(Serial2.available()){
      alarm = Serial2.read();
      if(alarm == 13)buzzer_mode = false;
      lastButtonState = 0;
  }

To distinguish between the two cases, add a logger to the place where messages arrive in your Clock Timer.

Here are 3 sample loggers ...

1 Like

How do I make a logger distinguish between the two cases? I don't understand... I'm sorry i'm quite slow...

The value 13 does not start the alert but rather stops it. bc when the value 13 is received from the app, it should tell the arduino to stop the buzzed and blinking LED's as well as clear the LCD

Show us your new blocks.

Please download and post each of those event block(s)/procedures here ...
(sample video)

1 Like

ECMS2_revised (4).aia (1.1 MB)

Here you go sir, i'm sorry again for being a nuisance :confused:

Just your Clock.Timer event block, please ...

Please download and post each of those event block(s)/procedures here ...
(sample video)

1 Like

Hello, sorry for the late reply. I was trying to test back my old project that worked but the same issues appeared where when the bluetooth is connected it'll then immediately show both button's emergency text. So i looked back at videos of the project and did everything back the way it was then figured out that my button placement was wrong. The wires of the 5v were placed at the same legs of the digital pins. So then I fixed that and everything was fine on my old project.

Then I brought it to my project now but the errors still occured, then I tried comparing the old and new project, the old project used a while test do, so I added the code and holy frick it worked!!

Here is the blocks now:

Buuuttt there is still one problem... when clicking the button in the app that should stop the alarm, yes it works but only for the app, the arduino does not receive it so the buzzer and led still buzzes and blinks unless I click on the button again, only then it'll stop