Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /*
  2. Communication par bluetooth avec un HC-06
  3. On allume ou éteint deux LEDs en communiquant avec le moniteur série
  4. Le Nucleo retourne l'était actuel des 2 LEDs
  5. */
  6.  
  7. #include "mbed.h"
  8.  
  9.  
  10. Serial bluetooth(D8, D2); // module HC-06 branché à D8 (TX) et D2 (RX)
  11.  
  12. DigitalOut led_1(D3); // LED 1 branchée à D3
  13. DigitalOut led_2(D4); // LED 2 branchée à D4
  14.  
  15.  
  16. int main()
  17. {
  18. while(1) {
  19.  
  20. char c = bluetooth.getc();
  21. if(c == 'a') {
  22. led_1 = 1; // On allume la LED 1
  23. led_2 = 0; // On éteint la LED 2
  24. bluetooth.printf("LED 1 allumee, LED 2 eteinte.\n");
  25. }
  26. if(c == 'b') {
  27. led_1 = 0; // On éteint la LED 1
  28. led_2 = 1; // On allume la LED 2
  29. bluetooth.printf("LED 1 eteinte, LED 2 allumee.\n");
  30. }
  31. if(c == 'c') {
  32. led_1 = 1; // On allume la LED 1
  33. led_2 = 1; // On allume la LED 2
  34. bluetooth.printf("Les deux LEDs sont allumees.\n");
  35. }
  36. if(c == 'd') {
  37. led_1 = 0; // On éteint la LED 1
  38. led_2 = 0; // On éteint la LED 2
  39. bluetooth.printf("Les deux LEDs sont eteintes.\n");
  40. }
  41. if(c == 'e') {
  42. led_1 = !(led_1);
  43. led_2 = !(led_2);
  44. bluetooth.printf("Les deux LEDs ont change d'etat.\n");
  45. }
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement