Translate

Commande bluetooth



Le Sketch:

     //  --------------------------------------------------------------------------------
 // Commande Bluetooth
 //By Jojo Bricolo
// Mon-arduino.blogspot.com
// 09/07/2013

int Pin1 = 2;
int Pin2 = 3;
int Pin3 = 4;
int Pin4 = 5;
int Pin5 = 6;
int Pin6 = 7;
int Pin7 = 8;
int Pin8 = 9;


int state;
int flag=0;

void setup() {

pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(Pin3, OUTPUT);
pinMode(Pin4, OUTPUT);
pinMode(Pin5, OUTPUT);
pinMode(Pin6, OUTPUT);
pinMode(Pin7, OUTPUT);
pinMode(Pin8, OUTPUT);



Serial.begin(9600);
}

void loop() {

if(Serial.available() > 0){
state = Serial.read();
flag=0;
}

if (state == 'a') {  //  a = commande de marche led 1
digitalWrite(Pin1, HIGH);
if(flag == 0){
Serial.println("Led 1: 0N");
flag=1;
}
}

else if (state == 'q') { // q = commande d' arrêt led 1
digitalWrite(Pin1, LOW);
if(flag == 0){
Serial.println("Led 1: OFF");
flag=1;
}
}

if (state == 'z') {
digitalWrite(Pin2, HIGH);
if(flag == 0){
Serial.println("Led 2: 0N");
flag=1;
}
}

else if (state == 's') {
digitalWrite(Pin2, LOW);
if(flag == 0){
Serial.println("Led 2: OFF");
flag=1;
}
}


if (state == 'e') {
digitalWrite(Pin3, HIGH);
if(flag == 0){
Serial.println("Led 3: 0N");
flag=1;
}
}

else if (state == 'd') {
digitalWrite(Pin3, LOW);
if(flag == 0){
Serial.println("Led 3: OFF");
flag=1;
}
}
if (state == 'r') {
digitalWrite(Pin4, HIGH);
if(flag == 0){
Serial.println("Led 4: 0N");
flag=1;
}
}

else if (state == 'f') {
digitalWrite(Pin4, LOW);
if(flag == 0){
Serial.println("Led 4: OFF");
flag=1;
}
}
if (state == 't') {
digitalWrite(Pin5, HIGH);
if(flag == 0){
Serial.println("Led 5: 0N");
flag=1;
}
}

else if (state == 'g') {
digitalWrite(Pin5, LOW);
if(flag == 0){
Serial.println("Led 5: OFF");
flag=1;
}
}
if (state == 'y') {
digitalWrite(Pin6, HIGH);
if(flag == 0){
Serial.println("Led 6: 0N");
flag=1;
}
}

else if (state == 'h') {
digitalWrite(Pin6, LOW);
if(flag == 0){
Serial.println("Led 6: OFF");
flag=1;
}
}
if (state == 'u') {
digitalWrite(Pin7, HIGH);
if(flag == 0){
Serial.println("Led 7: 0N");
flag=1;
}
}

else if (state == 'j') {
digitalWrite(Pin7, LOW);
if(flag == 0){
Serial.println("Led 7: OFF");
flag=1;
}
}
if (state == 'i') {
digitalWrite(Pin8, HIGH);
if(flag == 0){
Serial.println("Led 8: 0N");
flag=1;
}
}

else if (state == 'k') {
digitalWrite(Pin8, LOW);
if(flag == 0){
Serial.println("Led 8: OFF");
flag=1;
}
}


}
 // ----------------------------------------------------------------------------------------------------------

Dans ce Sketch je commande 4 sorties:

- "a" = Allumage sortie 1
- "q" = Extinction sortie 1
- "z" = Allumage sortie 2
- "s" = Extinction sortie 2
- "e" = Allumage sortie 3
- "d" = Extinction sortie 3
- "r" = Allumage sortie 4
- "f" = Extinction sortie 4



Aucun commentaire:

Enregistrer un commentaire