Skip to content

Instantly share code, notes, and snippets.

@jecrespo
Created April 18, 2020 08:18
Show Gist options
  • Save jecrespo/487c77e6815f0b960e68c5ca2701a727 to your computer and use it in GitHub Desktop.
Save jecrespo/487c77e6815f0b960e68c5ca2701a727 to your computer and use it in GitHub Desktop.
#include <LiquidCrystal.h>
byte const interruptPin2 = 2;
byte const interruptPin3 = 3;
int estado;
int cuenta;
unsigned long inicial;
int minutos;
int segundos;
int horas;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
void setup() {
pinMode(interruptPin2, INPUT_PULLUP);
pinMode(interruptPin3, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin2), salida, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin3), stop1, FALLING);
//fijar número la pantalla del LCD de filas y columnas:
lcd.begin (16, 2);
lcd.setCursor(1, 0);
lcd.print ("tiempo transcurrido:");
lcd.setCursor(3, 1);
lcd.print(":");
lcd.setCursor(7, 1);
lcd.print(":");
lcd.setCursor(11, 1);
lcd.print(":");
}
void loop() {
inicial = millis();
segundos = 0;
minutos = 0;
horas = 0;
while (estado) {
int count = millis() - inicial;
if (count > 999) {
inicial += 1000;
segundos++;
if (segundos > 59) {
segundos = 00;
lcd.setCursor(9, 1);
lcd.print("");
minutos ++;
if (minutos > 59) {
minutos = 0;
lcd.setCursor(5, 1);
lcd.print("");
horas ++;
}
}
}
lcd.setCursor(0, 1);
lcd.print(horas);
lcd.setCursor(4, 1);
lcd.print(minutos);
lcd.setCursor(8, 1);
lcd.print(segundos);
lcd.setCursor(12, 1);
lcd.print(count);
}
}
void salida() {
estado = 1;
}
void stop1() {
estado = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment