gestion_de_3_leds_via_bluetooth
                Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| gestion_de_3_leds_via_bluetooth [2017/05/07 14:26] – simon | gestion_de_3_leds_via_bluetooth [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ====== Gestion de trois leds via bluetooth ====== | ||
| - | Suite à notre découverte du module bluetooth [[tel0026]] et à un premier essais [[allumer une led via bluetooth]], | ||
| - | ===== Mise en place ====== | ||
| - | * Arduino " | ||
| - | * Une [[https:// | ||
| - | * Avec un [[https:// | ||
| - | * Sur lequel on met un [[https:// | ||
| - | |||
| - | * Arduino " | ||
| - | * Une [[https:// | ||
| - | * Avec un [[https:// | ||
| - | * Sur lequel on met trois [[https:// | ||
| - | |||
| - | <WRAP center round important 60%> | ||
| - | **TODO:** Ajouter photos! | ||
| - | </ | ||
| - | |||
| - | ===== Code " | ||
| - | <code c> | ||
| - | /* Minimal code for testing bluetooth module TEL0026 with a joystick | ||
| - | |||
| - | The circuit is based on Dreamer Nano V4.1, compatible Arduino Leonardo ( https:// | ||
| - | TEL0026 and button are plugged on Nano I/O Shield ( https:// | ||
| - | |||
| - | Created 2017 by Simon Lefort. | ||
| - | */ | ||
| - | |||
| - | const int joyX = A0; | ||
| - | const int joyY = A1; | ||
| - | const int joyZ = 8; //button is on pin 8 | ||
| - | |||
| - | byte joyXValue = 0; | ||
| - | byte joyYValue = 0; | ||
| - | byte joyZValue = 0; | ||
| - | |||
| - | void setup() { | ||
| - | Serial.begin(38400); | ||
| - | Serial1.begin(38400); | ||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | //lecture des capteurs | ||
| - | joyXValue = analogRead(joyX) / 4; // | ||
| - | joyYValue = analogRead(joyY) / 4; | ||
| - | joyZValue = digitalRead(joyZ); | ||
| - |  | ||
| - | //envoi | ||
| - | Serial1.write(" | ||
| - | Serial1.write(joyXValue); | ||
| - | Serial1.write(" | ||
| - | Serial1.write(joyYValue); | ||
| - | Serial1.write(" | ||
| - | Serial1.write(joyZValue); | ||
| - | Serial1.println(); | ||
| - |  | ||
| - | //debug | ||
| - | Serial.print(" | ||
| - | Serial.print(joyXValue); | ||
| - | Serial.print(" | ||
| - | Serial.print(joyYValue); | ||
| - | Serial.print(" | ||
| - | Serial.println(joyZValue); | ||
| - |  | ||
| - | delay(1000); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== Code " | ||
| - | <code c> | ||
| - | /* Minimal code for testing bluetooth module TEL0026 with leds. | ||
| - | |||
| - | This program must be used with " | ||
| - | |||
| - | The circuit is based on Arduino Mega 2560. TEL0026 and leds are plugged on a shield. | ||
| - | |||
| - | Created 2017 by Simon Lefort. | ||
| - | */ | ||
| - | |||
| - | int ledPinRed = 14; | ||
| - | int ledBrightX = 15; | ||
| - | int ledBrightY = 16; | ||
| - | int incomingByte = 0; | ||
| - | String chaine = ""; | ||
| - | |||
| - | byte xValue = 0; | ||
| - | byte yValue = 0; | ||
| - | byte zValue = 0; | ||
| - | |||
| - | void setup() { | ||
| - | Serial.begin(38400); | ||
| - | Serial1.begin(38400); | ||
| - |  | ||
| - | digitalWrite(ledPinRed, | ||
| - | digitalWrite(ledPinRed, | ||
| - | digitalWrite(ledPinRed, | ||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | if (Serial1.available() > 0){ | ||
| - | incomingByte = Serial1.read(); | ||
| - | delay(20); | ||
| - | chaine.concat(incomingByte); | ||
| - |  | ||
| - | if (isAlpha(incomingByte)){ | ||
| - | Serial.write(incomingByte); | ||
| - | Serial.print(" | ||
| - |  | ||
| - | if(incomingByte == ' | ||
| - | xValue = Serial1.read(); | ||
| - | delay(10); | ||
| - | chaine.concat(xValue); | ||
| - | Serial.println(xValue); | ||
| - | } | ||
| - | else if(incomingByte == ' | ||
| - | yValue = Serial1.read(); | ||
| - | delay(10); | ||
| - | chaine.concat(yValue); | ||
| - | Serial.println(yValue); | ||
| - | } | ||
| - | else if(incomingByte == ' | ||
| - | zValue = Serial1.read(); | ||
| - | delay(10); | ||
| - | chaine.concat(zValue); | ||
| - | Serial.println(zValue); | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | if(chaine != "" | ||
| - | if(incomingByte == 10 || chaine.length() > 28){ | ||
| - | //Debug: | ||
| - | Serial.println(chaine); | ||
| - |  | ||
| - | chaine = ""; | ||
| - | xValue = 0; | ||
| - | yValue = 0; | ||
| - | zValue = 0; | ||
| - | } | ||
| - | } | ||
| - | } | ||
| - | |||
| - | /* NOTES: | ||
| - | Ce qu'on lit dans le terminal série : | ||
| - | |||
| - | X 126 | ||
| - | Y 129 | ||
| - | Z 1 | ||
| - | 88126891299011310 | ||
| - | |||
| - | */ | ||
| - | </ | ||
gestion_de_3_leds_via_bluetooth.1494167196.txt.gz · Dernière modification :  (modification externe)
                
                