Tuto app inventor / arduino

App Inventor — LED Bluetooth — anglais

1. Elements à mettre et à nommer

Dans User Interface

Élément à glisserRenommer enText
ListPickerListPicker_BTConnect Bluetooth
ButtonButton_ONON
ButtonButton_OFFOFF
LabelLabel_StatusNot connected

Dans Connectivity

Élément à glisserRenommer en
BluetoothClientBluetoothClient1

2. Blocks

Cliquer sur Blocks.


3. Bloc connexion : liste Bluetooth

Cliquer sur ListPicker_BT.

Prendre :

when ListPicker_BT.BeforePicking

Ajouter :

set ListPicker_BT.Elements to BluetoothClient1.AddressesAndNames

Bloc complet :

when ListPicker_BT.BeforePicking
do set ListPicker_BT.Elements to BluetoothClient1.AddressesAndNames

4. Bloc connexion : choisir HC-05

Cliquer sur ListPicker_BT.

Prendre :

when ListPicker_BT.AfterPicking

Ajouter :

call BluetoothClient1.Connect address ListPicker_BT.Selection

Ajouter :

set Label_Status.Text to "Connected"

Bloc complet :

when ListPicker_BT.AfterPicking
do call BluetoothClient1.Connect address ListPicker_BT.Selection
set Label_Status.Text to "Connected"

5. Bloc bouton ON

Cliquer sur Button_ON.

Prendre :

when Button_ON.Click

Ajouter :

if BluetoothClient1.IsConnected
then call BluetoothClient1.SendText text "1"

Bloc complet :

when Button_ON.Click
do if BluetoothClient1.IsConnected
then call BluetoothClient1.SendText text "1"

6. Bloc bouton OFF

Cliquer sur Button_OFF.

Prendre :

when Button_OFF.Click

Ajouter :

if BluetoothClient1.IsConnected
then call BluetoothClient1.SendText text "0"

Bloc complet :

when Button_OFF.Click
do if BluetoothClient1.IsConnected
then call BluetoothClient1.SendText text "0"

7. Résultat

ON  → envoie 1 → LED allumée
OFF → envoie 0 → LED éteinte