-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHC05_Led_On_Off.ino
More file actions
75 lines (64 loc) · 2.05 KB
/
HC05_Led_On_Off.ino
File metadata and controls
75 lines (64 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* Test Bluetooth avec le module HC05
*
* LED en Pin 7 du Uno.
*
* Le HC05 en TX=10 et RX=11
* La Pin EN = 9
* Pin STATE = Pas connectée.
* +5V et Masse.
*
* Ouvrir le terminal.
*
* Charger l'Apps : Bluetooth Terminal HC-05 de mightyIT sur votre smartphone.
*
* Sur "Enter ASCII Command" tappez : on ou off, la Led s'allume ou s'eteints.
* Le resultat apparait dans le terminal.
*
*/
#include <SoftwareSerial.h> // librairie pour creer une nouvelle connexion serie max 9600 baud
#define PIN_LED 7 // Led sur le port 7.
SoftwareSerial BTSerial(10, 11); // BT-TX=10 et BT-RX=11
// Le S E T U P :
// ==============
void setup()
{
Serial.begin(9600); // Moniteur série à 9600 Bauds.
Serial.println("Commande en attente : ");
BTSerial.begin(9600); // BT : HC-05 à 9600 Bauds.
pinMode(PIN_LED, OUTPUT); // LED sur Port 7.
}
// La B O U C L E :
// ================
void loop()
{
String message; // Chaine : message
// Boucle de lecture sur le BT :
while (BTSerial.available())
{
// Lecture du message envoyé par le BT
message = BTSerial.readString();
// Ecriture du message dans le serial usb
Serial.print("Etat de la LED = ");
Serial.println(message);
}
// Boucle de lecture sur le serial usb
while (Serial.available())
{
// Lecture du message envoyé par le serial usb
message = Serial.readString();
// Ecriture du message dans le BT
Serial.print("Etat de la LED = ");
BTSerial.print(message);
}
// si mon message est egal a "on" ( + retour chariot et nouvelle ligne )
if(message == "on\r\n")
{
digitalWrite(PIN_LED,HIGH); // led on
}
// Si non, le message est egal a "off"
else if(message == "off\r\n")
{
digitalWrite(PIN_LED,LOW); // led off
}
}