Created
May 5, 2017 18:54
-
-
Save HectorTorres/e874ead4c0222dbd3c360c2cfb9ab250 to your computer and use it in GitHub Desktop.
arduino bluetooth
This file contains 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
//bluetooth hc-06 | |
int ledPin = 12; // usamos un pin de salida al LED | |
int state = 0; // Variable lectrura serial | |
void setup() { | |
pinMode(ledPin, OUTPUT); //Declara pin de Salida | |
digitalWrite(ledPin, LOW); //Normalmente Apagado | |
Serial.begin(9600); | |
} | |
void loop() { | |
//si el modulo a manda dato, guardarlo en estado. | |
if(Serial.available() > 0){ | |
state = Serial.read(); | |
} // esta parte del código es para solo 1 Carácter o Unidad. | |
// si el estado es 0 ese sería Apagado “OFF” | |
if (state == '0') { | |
digitalWrite(ledPin, LOW); | |
Serial.println("LED: off"); | |
} | |
// de lo contrario si el estado es 1 ese sería Encendido “ON” | |
else | |
if (state == '1') { | |
digitalWrite(ledPin, HIGH); | |
Serial.println("LED: on"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment