Skip to content

Instantly share code, notes, and snippets.

@HectorTorres
Created May 5, 2017 18:54
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
  • Save HectorTorres/e874ead4c0222dbd3c360c2cfb9ab250 to your computer and use it in GitHub Desktop.
Save HectorTorres/e874ead4c0222dbd3c360c2cfb9ab250 to your computer and use it in GitHub Desktop.
arduino bluetooth
//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