DIGITAL INPUTS PRACTICE
In the following practice you will find the 3 actions of Digital Inputs : Events, States and Interruption, in which by Tinkercad we develop a simulation for each one, that shows the fuctionality of each action. In the action: Interruption you an example of how to send a SOS message by the Morse Lenguage.
The following image show how is the circuit connect:
1. States:
//States/
void setup (){
pinMode (LED_BUILTIN,OUTPUT) ;
pinMode (2, INPUT_PULLUP) ; //Resistencia Pull Up Interna
Serial. begin (9600);
Serial.println ("Inicia") ;
}
void loop (){
//Lectura de estados
// PULLUP INTERNA
if (digitalRead(2)==LOW) {
Serial.println ("INTERRUPTOR A LA IZQUIERDA") ;
}
else{
Serial.println ("INTERRUPTOR A LA DERECHA") ;
}
}
void setup (){
pinMode (LED_BUILTIN,OUTPUT) ;
pinMode (2, INPUT_PULLUP) ; //Resistencia Pull Up Interna
Serial. begin (9600);
Serial.println ("Inicia") ;
}
void loop (){
//Lectura de estados
// PULLUP INTERNA
if (digitalRead(2)==LOW) {
Serial.println ("INTERRUPTOR A LA IZQUIERDA") ;
}
else{
Serial.println ("INTERRUPTOR A LA DERECHA") ;
}
}
2. Events:
/Events/
bool banderaB=true;
void setup (){
pinMode (LED_BUILTIN,OUTPUT) ;
pinMode (3, INPUT) ; //Resistencia Pull Up Interna
Serial. begin (9600);
Serial.println ("Inicia") ;
}
void loop (){
//Lectura de eventos
// PULLUP INTERNA
if (digitalRead(3)==HIGH && banderaB==true) {
Serial.println ("FLANCO PRESIONAR BOTON PULLDOWN");
banderaB=false ;
delay(200);//Antirrebote
}
if (digitalRead(3)==LOW && banderaB==false) {
Serial.println ("FLANCO SOLTAR BOTON PULLDOWN");
banderaB=true ;
delay(200);//Antirrebote
}
}
bool banderaB=true;
void setup (){
pinMode (LED_BUILTIN,OUTPUT) ;
pinMode (3, INPUT) ; //Resistencia Pull Up Interna
Serial. begin (9600);
Serial.println ("Inicia") ;
}
void loop (){
//Lectura de eventos
// PULLUP INTERNA
if (digitalRead(3)==HIGH && banderaB==true) {
Serial.println ("FLANCO PRESIONAR BOTON PULLDOWN");
banderaB=false ;
delay(200);//Antirrebote
}
if (digitalRead(3)==LOW && banderaB==false) {
Serial.println ("FLANCO SOLTAR BOTON PULLDOWN");
banderaB=true ;
delay(200);//Antirrebote
}
}
3. Interruptions:
//interruptions/
void setup (){
pinMode (2, INPUT_PULLUP) ; //Resistencia Pull Up Interna
Serial.begin (9600);
attachInterrupt(digitalPinToInterrupt(2), mostrar, CHANGE);
}
void loop (){
void setup (){
pinMode (2, INPUT_PULLUP) ; //Resistencia Pull Up Interna
Serial.begin (9600);
attachInterrupt(digitalPinToInterrupt(2), mostrar, CHANGE);
}
void loop (){
}
void mostrar() {
Serial.println("BOTON 1 CAMBIO");
}
void mostrar() {
Serial.println("BOTON 1 CAMBIO");
}
In this action, we connect the circuit
The following code shows how to make an SOS Help signal on TinkerCad:
const int LED=13;
void setup()
{
//pinMode(2,INPUT_PULLUP);
pinMode(LED,OUTPUT);
Serial.begin(9600);
//attachInterrupt(digitalPinToInterrupt(2), mostrar, CHANGE);
}
{
//pinMode(2,INPUT_PULLUP);
pinMode(LED,OUTPUT);
Serial.begin(9600);
//attachInterrupt(digitalPinToInterrupt(2), mostrar, CHANGE);
}
void loop()
{
mostrar(400);
mostrar(800);
mostrar(400);
delay(2000);
}
{
mostrar(400);
mostrar(800);
mostrar(400);
delay(2000);
}
void mostrar(int duracion)
{
Serial.println("BOTON 1 CAMBIO");
for (int i=1; i <= 3; i++)
{
digitalWrite(LED,HIGH); //se enciende el LED
delay(duracion); //tiempo de parpadeo
digitalWrite(LED,LOW); //se apaga el LED
delay(duracion);
}
}
{
Serial.println("BOTON 1 CAMBIO");
for (int i=1; i <= 3; i++)
{
digitalWrite(LED,HIGH); //se enciende el LED
delay(duracion); //tiempo de parpadeo
digitalWrite(LED,LOW); //se apaga el LED
delay(duracion);
}
}
Finally, we show the video of the simulation: