33.- Two Screens. Screen1 to Connect. Screen2 to view data.
p9A02_bluetooth_dospantallas.aia (5.5 KB)
For the app to work it must be installed.
- We can go from one screen to another without losing the connection.
// Juan A. Villalpando
// http://kio4.com/appinventor/9A02_Bluetooth_Dos_pantallas.htm
#include <SoftwareSerial.h>
SoftwareSerial BT(2,3);
int number = 0;
String numberS = "0";
char caracter = '0';
void setup(){
BT.begin(9600);
Serial.begin(9600);
}
void loop(){
// Send number every 800 ms.
delay(800);
number = number + 1;
if(number == 1000){number = 0;}
Serial.println(number);
numberS = (String) number + '\n';
BT.write(numberS.c_str());
// If receive char 'r' by BT, restart number.
if(BT.available()) {
caracter = BT.read();
Serial.println(caracter);
if(caracter == 'r'){number = 0;}
}
}
- Sketch sends a number by BT every 800 ms: 1 2 3 4 5 6 7 8...
- If this code receives the character 'r' by BT, the count is reset (number = 0)
ooooooooooooooooooooooooooooooooooooooooooooooooooo
- Screen1 Select and Connect BT.
- Receives the numbers by BT and store them in a comma separated string in a TinyDB, Always in the ReceiveText tag. 1,2,3,4,5,6,7,8,...
- Shows all data in Label etq_receive.
- Button "Open Screen2" open this screen.
oooooooooooooooooooooooooooooooooooooooooooooooo
- Screen2 shows in Label etq_receive all data of TinyDB, ReceiveText tag.
- TinyDB1 is the same on both screens, since they have the same NameSpace.
- Button: "Send 'r' (by Screen1)", close Screen2 and sends 'r' to Screen1.
- When Screen1 receive 'r', SendText 'r' by BT to Arduino. Arduino reset (number = 0). Return to Screen2.
ooooooooooooooooooooooooooooooooo
Similar to this topic: [Extension] Dynamic graph. Shift left graph. Sinusoidal wave. Bluetooth - #13 by Juan_Antonio



