Created
October 3, 2019 15:46
-
-
Save parzibyte/a6ffed7c2ba30086f7f3ade30788620a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 un número 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? | |
int numero = Serial.parseInt(); //Si es que sí, lo leemos y lo convertimos a entero | |
if (numero >= 0 && numero < 256) { //Recordemos que sólo tenemos 1 byte, por lo que no podemos representar números más grandes que 255 | |
digitalWrite(PIN_LATCH, LOW); //Le decimos que vamos a escribir algo... | |
shiftOut(PIN_DATA, PIN_CLOCK, LSBFIRST, numero); //Escribimos el número 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