Created
October 3, 2019 15:47
-
-
Save parzibyte/d764d66fc3a6066eab48c92082efacd9 to your computer and use it in GitHub Desktop.
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
/* | |
Escribir la representación binaria de un carácter proporcionado por el usuario a través de la comunicación Serial | |
@autor parzibyte | |
@web parzibyte.me | |
*/ | |
#define PIN_CLOCK 2 | |
#define PIN_LATCH 3 | |
#define PIN_DATA 4 | |
void setup() { | |
/* | |
Al final de todo, son pines de salida, | |
y debemos establecerlos como tal | |
*/ | |
pinMode(PIN_CLOCK, OUTPUT); | |
pinMode(PIN_LATCH, OUTPUT); | |
pinMode(PIN_DATA, OUTPUT); | |
Serial.begin(9600); //Comenzar comunicación serial | |
} | |
void loop() { | |
/* | |
Vamos a hacer lo mismo pero ahora en un ciclo, y dentro de loop, para que cuando llegue a 255 inicie de nuevo | |
*/ | |
if (Serial.available()) { //¿Hay algo que leer en el serial? | |
char caracter = Serial.read(); //Si es que sí, lo leemos. En este caso la variable será de tipo char | |
if (caracter >= 0 && caracter < 256) { //Recordemos que sólo tenemos 1 byte, por lo que no podemos representar carácteres cuyo código no esté entre 0 y 255 | |
digitalWrite(PIN_LATCH, LOW); //Le decimos que vamos a escribir algo... | |
shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, caracter); //Escribimos el carácter que el usuario proporcionó | |
digitalWrite(PIN_LATCH, HIGH) ; //Y le indicamos que lo guarde | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment