Contrôle De Deux LEDs Par Bluetooth (HC-06) - Gist Github

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@ypelletier ypelletier/bluetooth_controle_2_LEDs.ino Last active February 16, 2017 17:48 Show Gist options
  • Star (0) You must be signed in to star a gist
  • Fork (0) You must be signed in to fork a gist
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/ypelletier/eec815c2ca5c2320a280.js"></script>
  • Save ypelletier/eec815c2ca5c2320a280 to your computer and use it in GitHub Desktop.
Code Revisions 2 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/ypelletier/eec815c2ca5c2320a280.js"></script> Save ypelletier/eec815c2ca5c2320a280 to your computer and use it in GitHub Desktop. Download ZIP Contrôle de deux LEDs par bluetooth (HC-06) Raw bluetooth_controle_2_LEDs.ino This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
/* Contrôle de deux LEDs par bluetooth
Module bluetooth HC-06
LED branchée à la pin 8
LED branché à la pin 9
http://electroniqueamateur.blogspot.ca/2016/03/bluetooth-et-arduino-le-module-hc-06.html
*/
#define LEDpin1 8
#define LEDpin2 9
char instruction; // le message recu par bluetooth;
int etatLED1 = 0, etatLED2 = 0;
void setup()
{
Serial.begin(9600);
pinMode(LEDpin1, OUTPUT);
pinMode(LEDpin2, OUTPUT);
}
void loop()
{
char message;
if (Serial.available()) // réception d'un message
{
message = Serial.read(); // lecture du message reçu
}
if (message != instruction) { // alors c'est un nouveau message
instruction = message;
if (instruction == 'a')
{
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, LOW);
etatLED1 = 1;
etatLED2 = 0;
Serial.println("LED 1 allumee, LED 2 eteinte");
}
else if (instruction == 'b')
{
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, HIGH);
etatLED1 = 0;
etatLED2 = 1;
Serial.println("LED 1 eteinte, LED 2 allumee");
}
else if (instruction == 'c')
{
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);
etatLED1 = 1;
etatLED2 = 1;
Serial.println("Les 2 LEDs allumees");
}
else if (instruction == 'd')
{
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, LOW);
etatLED1 = 0;
etatLED2 = 0;
Serial.println("Les 2 LEDs eteinte");
}
else if (instruction == 'e')
{
digitalWrite(LEDpin1, !etatLED1);
digitalWrite(LEDpin2, !etatLED2);
etatLED1 = !etatLED1;
etatLED2 = !etatLED2;
Serial.println("Les 2 LEDs ont change d'etat");
}
delay(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Tag » Arduino Hc-06 Led