salut à tous ,
hier j'ai acheter un module hc-06 et j'ai télécharger une applis sur android compatible avec le module
après j'ai uploder le code suivant :
#define ledPin 7
int state = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");;
state = 0;
}
}
jusqu’à la je peux allumer une led et l’éteindre
maintenant je veux allumer et éteindre
ET allumer une autre led avec un autre bouton donc j'ai fait quelque modification :
#define ledPin 7
#define ledPin 8
int state = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");;
state = 0;
}
if (state == 'led1') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == 'led0') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");;
state = 0;
}
}
eeeet ça na pas marcher !! (et oui il faut toujours avoir un prob dans un projet de robotique )
ma question ? la voila ...:
pourquoi ça ne marche pas après la modification
pour info les valeur à envoyer au module HC-06 sont correctement entrer dans l'appli
le lien de l'appli : https://play.google.com/store/apps/details?id=com.arduino.bluecontrol&hl=fr
merci et bonne fin d'année 2016 !!