Campeonato de Barista preparación cronómetro • Introducción (4 / 7 paso)

Paso 4: código

El código siguiente debe ser copiado y pegado en el IDE de Arduino y luego, si se hizo algunos cambios necesarios, debe cargarse en la placa Arduino.

Descarga directa como .ide archivo, haga clic en este enlace.

 // ========== // World Barisa Championship brew time stopper // coded and designed by Tamas Szekffy // 2v0 as of 15. march 2014. // For improvements, notes, hints and bug reports, please contact professzore // Creative Commons Licence Attribution Non-Commercial Share Alike (CC-BY-NC-SA-4.0) // ========== // included Libraries #include // Basic LCD library #include // I2C Wiring library #include // MAX7221 library // ========== // pre-Setup // ========== LiquidCrystal lcd(8, 9, 5, 4, 3, 2); // LCD pinout const byte dot = B10100101; const byte full = B11111111; const int LCDBK = 6; // LCD Backlight pin const int ss1 = A3; // Start/Stop 1 pin const int ss2 = A2; // Start/Stop 2 pin const int rst = A1; // Reset pin int bcklght = 200; // LCD Backlight value (0 = turn off backlight) // Timer variables boolean timer1 = false; // true, if timer1 is running boolean timer2 = false; // true, if timer2 is running boolean ssastate = false; // became true, if ss1 button pressed (used for debouncing) boolean ssbstate = false; // became true, if ss2 button pressed (used for debouncing) boolean rststate = false; // became true, if rst button pressed (used for debouncing) boolean finish = false; // became true, as soon as all measurements finished unsigned long atime; // temporary variable for first time, indicates the time spent since start unsigned long btime; // temporary variable for second time, indicates the time spent since start unsigned long astime; // variable for first time, indicates the time when stopper started unsigned long bstime; // variable for second time, indicates the time when stopper started unsigned long debounce; int atimes[3]; // arrays of variables to store first time measured, one after another int btimes[3]; // arrays of variables to store second time measured, one after another int validtime = 3000; // maximum time allowed as difference between measured times to meet WBC rules (milliseconds, 3 sec = 3000) unsigned long menudelay = 0; // variable to measure the time how long "reset" pressed boolean menustate = false; // boolean variable to point out if the system is in MENU mode for validation time boolean menustate2 = false; // boolean variable to point out if the system is in MENU mode for backlight setting time byte atimecount = 0; // variable to count which measurement (first, second or first) are 'in line' for first time byte btimecount = 0; // variable to count which measurement (first, second or first) are 'in line' for second time /* pin 11 is connected to the DataIn pin 13 is connected to the CLK pin 10 is connected to LOAD We have only a single (1) MAX72XX. */ LedControl lc=LedControl(11,13,10,1); // =========== // Main Setup // =========== void setup() { Wire.begin(); // Turn on I2C analogWrite(LCDBK, bcklght); // LCD backlight is ON lcd.begin(16, 2); // set the size of the LCD (16 digits, 2 rows) lcd.clear(); /* The MAX72XX is in power-saving mode on startup, we have to do a wakeup call */ lc.shutdown(0,false); /* Set the brightness */ lc.setIntensity(0,8); /* and clear the display */ lc.clearDisplay(0); pinMode(ss1, INPUT); pinMode(ss2, INPUT); pinMode(rst, INPUT); // testrun(); // unmark '//' if you need the initial test of the system // delay(1); lcd.clear(); lcd.setCursor(0,0); lcd.print("WBC valid time"); lcd.setCursor(0,1); lcd.print(validtime); lcd.print(" msec"); delay(2000); lcd.clear(); rstall(); } // ============= // Main routine // ============= void loop() { if (digitalRead(ss1) == HIGH && ssastate == false && finish != true && debounce + 200 < millis()) { startstopa(); debounce = millis(); } if (digitalRead(ss1) == LOW && ssastate == true) { ssastate = false; } if (digitalRead(ss2) == HIGH && ssbstate == false && finish != true && debounce + 200 < millis()) { startstopb(); debounce = millis(); } if (digitalRead(ss2) == LOW && ssbstate == true) { ssbstate = false; } if (digitalRead(rst) == HIGH && rststate == false && finish == true && debounce + 200 < millis()) { rstall(); debounce = millis(); finish = false; menudelay = 0; } if (digitalRead(rst) == HIGH && rststate == false && finish == false && menudelay == 0) { menudelay = millis() + 3000; rststate = true; } if (digitalRead(rst) == HIGH && rststate == true && menudelay != 0 && menudelay < millis()) { menustate = true; lcd.clear(); } if (digitalRead(rst) == LOW && rststate == true) { rststate = false; menudelay = 0; } if (atimecount == btimecount && atimecount != 0) { validate(); } if (atimecount == 3 && btimecount == 3) { finish = true; } // ============================ // Time check value setup/menu // ============================ while(menustate) { lc.clearDisplay(0); lcd.setCursor(0,0); lcd.print("WBC valid time"); lcd.setCursor(0,1); lcd.print(validtime); lcd.print(" msec "); if (digitalRead(ss1) == HIGH && ssastate == false && validtime > 0 && debounce + 200 < millis()) { ssastate = true; validtime -= 100; debounce = millis(); } if (digitalRead(ss1) == LOW && ssastate == true) { ssastate = false; } if (digitalRead(ss2) == HIGH && ssbstate == false && validtime < 32700 && debounce + 200 < millis()) { ssbstate = true; validtime += 100; debounce = millis(); } if (digitalRead(ss2) == LOW && ssbstate == true) { ssbstate = false; } if (digitalRead(rst) == LOW && rststate == true) { rststate = false; menudelay = 0; } if (digitalRead(rst) == HIGH && rststate == false && menudelay == 0) { menustate = false; menustate2 = true; rststate = true; menudelay = millis() + 200; } } // END of submenu1 // ===================== // Backlight setup menu // ===================== while(menustate2) { lc.clearDisplay(0); lcd.setCursor(0,0); lcd.print("Backlight value"); lcd.setCursor(0,1); lcd.print(bcklght); lcd.print(" "); if (digitalRead(ss1) == HIGH && ssastate == false && bcklght > 0 && debounce + 200 < millis()) { ssastate = true; bcklght -= 10; debounce = millis(); } if (digitalRead(ss1) == LOW && ssastate == true) { ssastate = false; } if (digitalRead(ss2) == HIGH && ssbstate == false && bcklght < 250 && debounce + 200 < millis()) { ssbstate = true; bcklght += 10; debounce = millis(); } if (digitalRead(ss2) == LOW && ssbstate == true) { ssbstate = false; } if (digitalRead(rst) == LOW && rststate == true) { rststate = false; menudelay = 0; } if (digitalRead(rst) == HIGH && rststate == false && menudelay > millis()) { menustate2 = false; rststate = true; delay(1); rstall(); delay(1); } analogWrite(LCDBK, bcklght); } // END of submenu2 delay(1); } // ======================== // Start/stop of stopper 1 // ======================== void startstopa() { ssastate = true; // the button has pressed if (timer1 == false) // if the timer is NOT running... { astime = millis(); // record start time timer1 = true; // indicate the start of the timer lcd.setCursor(2,0); lcd.print("RUN"); lc.setChar(0,3,'-',false); } else // if the timer is running... { timer1 = false; // indicate the stop of the timer atime = millis() - astime; // calculates the time spent since start lcd.setCursor(2,0); lcd.print("..."); lc.setChar(0,3,' ',false); atime = atime/100; atime = atime * 100; atimes[atimecount] = atime; write7Segment(atimes[atimecount], 0); if (atimecount < 3) { lcd.setCursor(6+(atimecount*2),0); lcd.write(full); atimecount ++; } } } // ======================== // Start/stop of stopper 2 // ======================== void startstopb() { ssbstate = true; // the button has pressed if (timer2 == false) // if the timer is NOT running... { bstime = millis(); // record start time timer2 = true; // indicate the start of the timer lcd.setCursor(2,1); lcd.print("RUN"); lc.setChar(0,7,'-',false); } else // if the timer is running... { timer2 = false; // indicate the stop of the timer btime = millis() - bstime; // calculates the time spent since start lcd.setCursor(2,1); lcd.print("..."); lc.setChar(0,7,' ',false); btime = btime/100; btime = btime * 100; btimes[btimecount] = btime; write7Segment(btimes[btimecount], 4); if (btimecount < 3) { lcd.setCursor(6+(btimecount*2),1); lcd.write(full); btimecount ++; } } } // =================== // Write time on 7221 // =================== void write7Segment(unsigned long v, byte i) { byte ones; byte tens; byte fractions; v = v/100; fractions = v%10; v = v/10; ones = v%10; v = v/10; tens = v%10; lc.setDigit(0,i,tens,false); lc.setDigit(0,i+1,ones,true); lc.setDigit(0,i+2,fractions,false); } // ================================ // Validate each measurement-pairs // ================================ void validate() { unsigned int lowest; unsigned int highest; unsigned int difference; lowest = min(atimes[atimecount-1],btimes[btimecount-1]); highest = max(atimes[atimecount-1],btimes[btimecount-1]); difference = highest - lowest; if (difference > validtime) { lcd.setCursor(12,0); lcd.print("FAIL"); byte ones; byte tens; byte fractions; difference = difference/100; fractions = difference%10; difference = difference/10; ones = difference%10; difference = difference/10; tens = difference%10; lcd.setCursor(12,1); lcd.print(tens); lcd.setCursor(13,1); lcd.print(ones); lcd.setCursor(14,1); lcd.print('.'); lcd.setCursor(15,1); lcd.print(fractions); } else { lcd.setCursor(12,0); lcd.print(" OK "); byte ones; byte tens; byte fractions; difference = difference/100; fractions = difference%10; difference = difference/10; ones = difference%10; difference = difference/10; tens = difference%10; lcd.setCursor(12,1); lcd.print(tens); lcd.setCursor(13,1); lcd.print(ones); lcd.setCursor(14,1); lcd.print('.'); lcd.setCursor(15,1); lcd.print(fractions); } } // =========================================== // Reset all values, returns to initial state // =========================================== void rstall() { rststate = true; lc.clearDisplay(0); delay(100); write7Segment(0, 0); write7Segment(0, 4); //reset all variables timer1 = false; timer2 = false; atime = 0; btime = 0; astime = 0; bstime = 0; atimes[0] = 0; atimes[1] = 0; atimes[2] = 0; btimes[0] = 0; btimes[1] = 0; btimes[2] = 0; atimecount = 0; btimecount = 0; lcd.clear(); lcd.setCursor(0,0); lcd.print('1'); lcd.setCursor(0,1); lcd.print('2'); lcd.setCursor(2,0); lcd.print("..."); lcd.setCursor(2,1); lcd.print("..."); lcd.setCursor(6,0); lcd.write(dot); lcd.setCursor(8,0); lcd.write(dot); lcd.setCursor(10,0); lcd.write(dot); lcd.setCursor(6,1); lcd.write(dot); lcd.setCursor(8,1); lcd.write(dot); lcd.setCursor(10,1); lcd.write(dot); lcd.setCursor(12,0); lcd.print("...."); lcd.setCursor(12,1); lcd.print("...."); } // ======================================================================== // Test routine, may be started by un-// the call at the end of void.Setup // ======================================================================== void testrun() { lc.clearDisplay(0); lcd.clear(); lcd.setCursor(0,0); lcd.print("WBC Stopwatch"); lcd.setCursor(0,1); lcd.print("Made by Tamas Szekffy in 2014"); delay(2000); for (int scroll = 0; scroll < 18; scroll++) { lcd.scrollDisplayLeft(); delay(500); } lcd.clear(); lcd.setCursor(0,0); lcd.print("Test run will"); lcd.setCursor(0,1); lcd.print("undergo in 5 s"); delay(5000); lcd.clear(); lc.clearDisplay(0); for (int i = 0; i < 10; i++) { lc.setDigit(0,0,i,false); lc.setDigit(0,1,i,true); lc.setDigit(0,2,i,false); lc.setDigit(0,4,i,false); lc.setDigit(0,5,i,true); lc.setDigit(0,6,i,false); delay(500); } lc.clearDisplay(0); delay(500); lcd.clear(); delay(250); lcd.setCursor(0,0); lcd.print('1'); delay(250); lcd.setCursor(0,1); lcd.print('2'); delay(250); lcd.setCursor(2,0); lcd.print("..."); delay(250); lcd.setCursor(2,0); lcd.print("RUN"); delay(250); lcd.setCursor(2,1); lcd.print("..."); delay(250); lcd.setCursor(2,1); lcd.print("RUN"); delay(250); lcd.setCursor(6,0); lcd.write(dot); delay(250); lcd.setCursor(6,0); lcd.write(full); delay(250); lcd.setCursor(8,0); lcd.write(dot); delay(250); lcd.setCursor(8,0); lcd.write(full); delay(250); lcd.setCursor(10,0); lcd.write(dot); delay(250); lcd.setCursor(10,0); lcd.write(full); delay(250); lcd.setCursor(6,1); lcd.write(dot); delay(250); lcd.setCursor(6,1); lcd.write(full); delay(250); lcd.setCursor(8,1); lcd.write(dot); delay(250); lcd.setCursor(8,1); lcd.write(full); delay(250); lcd.setCursor(10,1); lcd.write(dot); delay(250); lcd.setCursor(10,1); lcd.write(full); delay(250); lcd.setCursor(12,0); lcd.print("...."); delay(250); lcd.setCursor(12,1); lcd.print("...."); delay(1000); lcd.clear(); lcd.setCursor(0,0); lcd.print("Ready to GO!"); delay(3000); lcd.clear();} 

Artículos Relacionados

Introducción a la depuración del microcontrolador (y un cronómetro Pomodoro)

Introducción a la depuración del microcontrolador (y un cronómetro Pomodoro)

Lectores de Hola Hack-A-Day y prototipos peligroso!  Por favor voten por mí en la uC de Sparkfun concurso!  (Si votas por mí puede todavía votar para otros proyectos así)  El botón de votación es justo arriba e izquierda de aquí... hay que ir... más.
Cronómetro de Arduino

Cronómetro de Arduino

Este Instructable le mostrará cómo hacer una parada de reloj de un Arduino.Paso 1: Lo que se necesitaVoluntad necesidad--1 x Arduino Uno http://store.arduino.cc/product/A000066-1 x protector de pantalla LCD teclado http://www.amazon.co.uk/SODIAL-Keyp
Cronómetro de basados en Arduino para pistas de carreras de coches eléctricas

Cronómetro de basados en Arduino para pistas de carreras de coches eléctricas

En este proyecto que estoy utilizando un sensor de proximidad infrarrojo a medida conectada a una placa Arduino el tiempo de las vueltas en un coche eléctrico circuito de carreras. El sensor detecta el coche cuando pasa delante de ella y mide el tiem
Cronómetro de Arduino fácil

Cronómetro de Arduino fácil

Hola. Voy a explicar cómo hace este cronómetro simple.Paso 1: conexionesEs de sólo conexión entre arduino y LCD 16 x 2.Igual que tutoriales de Arduino.cc"Pin RS del LCD para pin digital 12Pin Enable del LCD para pin digital 11D4 LCD pin a pin digital
HUEVO: El cronómetro futuro

HUEVO: El cronómetro futuro

Es la primera pregunta que usted puede preguntar, "¿por qué ' EGG'?" ¿Es un acrónimo? No. ¿El reloj está hecho de cáscara de huevo? No, aunque sería bastante sorprendente! Llamé a este reloj huevo simplemente porque tenía la ronda, presencia que
Controlado de radio del cronómetro

Controlado de radio del cronómetro

Como profesor y miembro de diversas organizaciones deportivas, he observado varios sistemas de tiempos diferentes, desde el tradicionales cronómetros independientes a sistemas coordinados más sofisticados (y caros) que al mismo tiempo tiempo, luego g
Cronómetro con microcontrolador ATmega328 de vuelta

Cronómetro con microcontrolador ATmega328 de vuelta

este instructable le mostrará cómo construir su propio cronómetro para registrar múltiples fracturas utilizando un microcontrolador programable ATmega328. Cuando uno presiona el botón de inicio (o abofetea a la banda de metal en mi reloj), la pantall
Sencillo cronómetro de Arduino

Sencillo cronómetro de Arduino

Un cronómetro de Arduino hace de un ejemplo existente de librería LiquidCrystal - Hola mundo. Te muestra el tiempo transcurrido desde reset. Este instructable es inspirado por el instructuble creado por Conor M - cronómetro de Arduino. Había despojad
Independiente Arduino cronómetro - protector de teclado de LCD SainSmart

Independiente Arduino cronómetro - protector de teclado de LCD SainSmart

así, para mi Instructable primera, también compartiré con ustedes mi primer proyecto: cronómetro de Arduino A independiente.Debo admitir que esto no fue creado por mí. Tomé la idea de otro cronómetro donde podrás leer la información en el puerto seri
Cronómetro automático

Cronómetro automático

Objetivo de este proyecto es contar el tiempo tomado por un escalador a escalar un muro. Pero debe ser automática, es decir escalador no tiene que empujar un botón para iniciar el temporizador/contador y también debe no realiza ningún esfuerzo para d
Un cronómetro digital

Un cronómetro digital

un simple cronómetro digital simulado en proteus y codificada en MikroC.Para obtener más información por favor visite mi sitio web.  
Cómo tener cronómetro y geolocalización en su sitio de Internet

Cómo tener cronómetro y geolocalización en su sitio de Internet

Puede tener cronómetro y geolocalización en tu página web usando html.Paso 1: geolocalización copia los siguientes códigos de la imagen y guarde el archivo como .html o .htmPaso 2: cronómetro copia los siguientes códigos de la imagen y guarde el arch
Cronómetro de PSP

Cronómetro de PSP

sí está aquí...El cronómetro de la PSPNo hay Custom Firmware necesitada...100% legal...Continúa incluso cuando el psp está apagado!!!!!!Paso 1: Conseguir los materialesSe necesita...UNA PSPAdaptador de adaptador USB o memory stickESTE archivo a conti
Cronómetro SPEEDsSTACK

Cronómetro SPEEDsSTACK

En este instructable voy a mostrar cómo hacer un cronómetro sensible táctil como cronómetro de SpeedStack.Ver funcionaPrimera prueba con el OLEDPaso 1: suministros de: * Arduino pro mini* Pantalla OLED Adafruit (128 * 68 i2c)* Cinta cobre* 2 Leds* 2