Regarding the signal sent from the app inventory to the Bluetooth module

#include <SoftwareSerial.h>
#include <Servo.h>

SoftwareSerial bluetooth(10, 11); // RX, TX 핀 설정

Servo motor1; //1번 모터 미쯔
Servo motor2; //2번 모터 조리퐁
Servo motor3; //3번 모터 코코볼
int counter = 0;

void setup() { //여기 부분은 모터 연결 및 블루투스 연결 부분
motor1.attach(2);
motor2.attach(3);
motor3.attach(4);
bluetooth.begin(9600);
}

void loop() { //숫자 데이터를 읽어와 카운터로 변환하는 과정
if (bluetooth.available()) {
char data = bluetooth.read();
if (data == '1') {
counter = 1;
} else if (data == '2') {
counter = 2;
} else if (data == '3') {
counter = 3;
}
}

switch (counter) { //카운터의 숫자에 따라 작동하는 모터와 작동 후 카운터를 0으로 초기화
case 1:
motor1.write(90);
delay(1000);
motor1.write(0);
counter = 0;
break;
case 2:
motor2.write(90);
delay(1000);
motor2.write(0);
counter = 0;
break;
case 3:
motor3.write(90);
delay(1000);
motor3.write(0);
counter = 0;
break;
default:
break;
}
}

This is the code
The Bluetooth model is HC-05
Press button 1 on the Bluetooth module
It's a signal of one
If you press button 2, you'll make the signal go
If you press the 3rd button, it makes the signal 3 go
I want to create a block in the app inventor
Please help me
It's a very urgent situation
Please, please, help me

Dear @baegineon
you could start from the "best in class" tutorial (though in spanish language) on @Juan_Antonio's web site:
http://kio4.com/appinventor/9A_bluetooth_appinventor_basico.htm
You will find there both Arduino code and AI2 blocks.
(90% of your job is already done in that tutorial, c/w hardware schematics).
Kind regards.

1 Like