Skip to content

Instantly share code, notes, and snippets.

@ypelletier
Last active February 16, 2017 17:48
Show Gist options
  • Save ypelletier/eec815c2ca5c2320a280 to your computer and use it in GitHub Desktop.
Save ypelletier/eec815c2ca5c2320a280 to your computer and use it in GitHub Desktop.
Contrôle de deux LEDs par bluetooth (HC-06)
/* 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