使用App Inventor 2開發藍牙(Bluetooth)Android app,接收從Arduino Mega2560傳送的資料,
這個範例許多網站也有提供類似內容,不過有些並沒有將App linentor 2與Arduino的程式碼一起提供,
首先demo app inventor 2的Designer與Block部分,
Designer,注意有加入藍芽與Timer,
Block部分,將接收的訊號傳到text1.text欄位中,
以下是Arduino code:
#include <SoftwareSerial.h>
#include <Wire.h>
SoftwareSerial I2CBT(10,11); //Rx,Tx
int potPin = 0; // Define the Analog input
void setup()
{
Serial.begin(9600);
I2CBT.begin(9600);
pinMode(potPin, INPUT);
}
void loop()
{
int value = analogRead(potPin); // read the value of the Analog Input
I2CBT.println(value);
Serial.println(value); // Print the value; can also be seen on Serial Monitor
delay(300); // Don't send too fast or the Android buffer will flood - this worked for me
}
使用可變電阻分壓,Mega2560的A0收到訊號號經由H06藍芽模組傳到手機,
手機App中收到的訊號會因分壓值的調整而有所改變,0~1023,
留言列表