Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Communication par bluetooth avec un HC-06
- On allume ou éteint deux LEDs en communiquant avec le moniteur série
- Le Nucleo retourne l'était actuel des 2 LEDs
- */
- #include "mbed.h"
- Serial bluetooth(D8, D2); // module HC-06 branché à D8 (TX) et D2 (RX)
- DigitalOut led_1(D3); // LED 1 branchée à D3
- DigitalOut led_2(D4); // LED 2 branchée à D4
- int main()
- {
- while(1) {
- char c = bluetooth.getc();
- if(c == 'a') {
- led_1 = 1; // On allume la LED 1
- led_2 = 0; // On éteint la LED 2
- bluetooth.printf("LED 1 allumee, LED 2 eteinte.\n");
- }
- if(c == 'b') {
- led_1 = 0; // On éteint la LED 1
- led_2 = 1; // On allume la LED 2
- bluetooth.printf("LED 1 eteinte, LED 2 allumee.\n");
- }
- if(c == 'c') {
- led_1 = 1; // On allume la LED 1
- led_2 = 1; // On allume la LED 2
- bluetooth.printf("Les deux LEDs sont allumees.\n");
- }
- if(c == 'd') {
- led_1 = 0; // On éteint la LED 1
- led_2 = 0; // On éteint la LED 2
- bluetooth.printf("Les deux LEDs sont eteintes.\n");
- }
- if(c == 'e') {
- led_1 = !(led_1);
- led_2 = !(led_2);
- bluetooth.printf("Les deux LEDs ont change d'etat.\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement