informatica:arduino:esp32:cronometro
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| informatica:arduino:esp32:cronometro [2023/04/17 12:13] – jose | informatica:arduino:esp32:cronometro [2023/04/17 23:14] (current) – jose | ||
|---|---|---|---|
| Line 81: | Line 81: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ====== Cronómetro con pulsador emergencia ====== | ||
| + | Empieza con 0:00:00\\ | ||
| + | Un click empieza a correr \\ | ||
| + | Segundo click para y deja valor en pantalla \\ | ||
| + | Tercer click vuelve al principio, vuelve a correr desde cero | ||
| + | |||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | /* | ||
| + | Valores pulsación: | ||
| + | | ||
| + | Inicial: | ||
| + | 1 click: | ||
| + | suelto: | ||
| + | 2 click: | ||
| + | suelto: | ||
| + | */ | ||
| + | |||
| + | |||
| + | //Vcc - Vcc | ||
| + | //Gnd - Gnd | ||
| + | //Din - Mosi (Pin 11) | ||
| + | //Cs - SS (Pin 10) | ||
| + | //Clk - Sck (Pin 18) | ||
| + | const int pinCS = 5; | ||
| + | |||
| + | // Dígitos del tiempo | ||
| + | int d=0; // décimas | ||
| + | int s=0; // unidad de segundo (s minúscula) | ||
| + | int S=0; // decenas de segundo (S mayúscula) | ||
| + | int m=0; // minutos | ||
| + | |||
| + | int apretado = 0; | ||
| + | int suelto = 1; | ||
| + | |||
| + | const int buttonPin = 4; // El pin donde está conectado el botón | ||
| + | |||
| + | |||
| + | int resetmillis=0; | ||
| + | |||
| + | const int numberOfHorizontalDisplays = 4; | ||
| + | //const int numberOfHorizontalDisplays = 1; // retirar comentario para una sola matriz | ||
| + | const int numberOfVerticalDisplays = 1; | ||
| + | Max72xxPanel matrix = Max72xxPanel(pinCS, | ||
| + | String tape = " | ||
| + | const int spacer = 1; | ||
| + | const int width = 5 + spacer; // The font width is 5 pixels | ||
| + | void setup() { | ||
| + | Serial.begin(115200); | ||
| + | |||
| + | pinMode(buttonPin, | ||
| + | |||
| + | matrix.setIntensity(7); | ||
| + | // | ||
| + | matrix.setPosition(0, | ||
| + | matrix.setPosition(1, | ||
| + | matrix.setPosition(2, | ||
| + | matrix.setPosition(3, | ||
| + | matrix.setRotation(0, | ||
| + | matrix.setRotation(1, | ||
| + | matrix.setRotation(2, | ||
| + | matrix.setRotation(3, | ||
| + | | ||
| + | resetmillis=millis(); | ||
| + | |||
| + | //Ponemos el contador a Cero | ||
| + | |||
| + | // | ||
| + | matrix.drawChar(23, | ||
| + | matrix.drawChar(9, | ||
| + | |||
| + | //Lo ponemos todo a CERO | ||
| + | matrix.drawChar(27, | ||
| + | matrix.drawChar(19, | ||
| + | matrix.drawChar(13, | ||
| + | matrix.drawChar(5, | ||
| + | |||
| + | matrix.write(); | ||
| + | |||
| + | } | ||
| + | void loop() { | ||
| + | | ||
| + | //Primero dibujamos los 2 puntos tape[10] son los puntos en la cadena tape y 9 y 23 la posición empezando a contar por la izquierda teniendo los pins a la izquierda y el 0 es la tercera columna | ||
| + | |||
| + | //Cada número ocupa 5 espacios, mas 1 de separación a cada lado | ||
| + | // | ||
| + | // | ||
| + | if (apretado == 1) { | ||
| + | |||
| + | matrix.drawChar(23, | ||
| + | matrix.drawChar(9, | ||
| + | |||
| + | int Tmillis=(millis()-resetmillis)/ | ||
| + | | ||
| + | int D = Tmillis/60; | ||
| + | int m = Tmillis/ | ||
| + | int S = Tmillis/ | ||
| + | int s = Tmillis/ | ||
| + | int d = Tmillis-m*600-S*100-s*10; | ||
| + | | ||
| + | matrix.drawChar(27, | ||
| + | matrix.drawChar(19, | ||
| + | matrix.drawChar(13, | ||
| + | matrix.drawChar(5, | ||
| + | |||
| + | matrix.write(); | ||
| + | } | ||
| + | |||
| + | |||
| + | // if (!digitalRead(buttonPin)) { // Si el botón está pulsado | ||
| + | if (digitalRead(buttonPin)) { // Si el botón está pulsado | ||
| + | if ( suelto == 1 ) { | ||
| + | suelto = 0; | ||
| + | if ( apretado == 1 ) { // Paro el cronómetro | ||
| + | apretado = 0; | ||
| + | } | ||
| + | else { // empieza el cronómetro | ||
| + | apretado = 1; | ||
| + | resetmillis=millis(); | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | else { | ||
| + | suelto = 1; | ||
| + | } | ||
| + | |||
| + | Serial.print(" | ||
| + | Serial.print(apretado); | ||
| + | Serial.print(" | ||
| + | Serial.println(suelto); | ||
| + | // | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ====== Webserver ====== | ||
| + | < | ||
| + | from http.server import BaseHTTPRequestHandler, | ||
| + | from urllib.parse import urlparse, parse_qs | ||
| + | from datetime import datetime | ||
| + | |||
| + | class MiServidor(BaseHTTPRequestHandler): | ||
| + | | ||
| + | def do_GET(self): | ||
| + | # Parsear la URL para obtener los parámetros | ||
| + | url = urlparse(self.path) | ||
| + | params = parse_qs(url.query) | ||
| + | | ||
| + | # Obtener el valor de la variable | ||
| + | variable = params.get(' | ||
| + | if variable is not None: | ||
| + | variable = variable[0] | ||
| + | | ||
| + | # Obtener la fecha actual en el formato deseado | ||
| + | fecha_actual = datetime.now().strftime(' | ||
| + | | ||
| + | # Guardar la fecha y el valor de la variable en el archivo | ||
| + | with open(' | ||
| + | archivo.write(f" | ||
| + | | ||
| + | # Responder con un código 200 | ||
| + | self.send_response(200) | ||
| + | self.end_headers() | ||
| + | | ||
| + | return | ||
| + | |||
| + | # Si no se especifica la variable, responder con un código 400 | ||
| + | self.send_response(400) | ||
| + | self.end_headers() | ||
| + | |||
| + | def iniciar_servidor(): | ||
| + | servidor = HTTPServer((' | ||
| + | print(' | ||
| + | servidor.serve_forever() | ||
| + | |||
| + | if __name__ == ' | ||
| + | iniciar_servidor() | ||
| + | </ | ||
| + | |||
| + | Se hace una petición: | ||
| + | curl localhost: | ||
| + | |||
informatica/arduino/esp32/cronometro.1681733629.txt.gz · Last modified: by jose
