Paso 7: Boceto final
Ahora tengo que poner todos los tres bosquejos juntos en un bosquejo de trabajo!
Solía el reloj dibujo como la base para añadir los otros dos bocetos para. He añadido funcionalidad al bloque iButtons y Arduino registrará las últimas 10 entradas.
El error que estaba en mi primer bosquejo se fija ahora. Si usted ha utilizado el código que fue publicado aquí antes de 02 de octubre de 2011, de cambiar este código. Si usted ya se ocupó vanamente con él, sólo hágamelo saber y voy a explicar una manera fácil de arreglar el fallo.
El boceto:
#include //adding the time-library #include //adding the LCD library #include //adding the iButton library LiquidCrystal lcd(11, 10, 5, 4, 3, 2); //the pins that the LCD is connected on int knoptijd = 400; //setting all the variables for the clock part(sorry for the Dutch names) int uur = 12; int minuut = 15; int seconde = 0; int dag = 10; int maand = 9; int jaar = 2011; int knopset = 9; int knopmode = 8; int setwaarde = 0; int modewaarde = 0; OneWire ds(12); //setting the variables for the iButton part byte addr[8]; int but1[6] = {0,149,107,48,13,0}; //*************the code of the iButtton**************** String name1 = "Burton"; //name should always be 6 digits byte uit1 = 1; int but2[6] = {0,65,177,47,13,0}; String name2 = "Aca "; byte uit2 = 1; int but3[6] = {0,235,75,138,9,0}; String name3 = "Peter "; byte uit3 = 1; int but4[6] = {0,3,0,0,0,0}; String name4 = "But 4 "; byte uit4 = 1; int but5[6] = {0,87,171,46,13,0}; String name5 = "Jelle "; byte uit5 = 1; String keyStatus=""; byte welkeBut = 0; String name = ""; String geheugen[10]= {"leeg10","leeg 9","leeg 8","leeg 7","leeg 6","leeg 5","leeg 4","leeg 3","leeg 2","leeg 1"}; int memHour[10]= {99,99,99,99,99,99,99,99,99,99}; int memMinute[10]= {99,99,99,99,99,99,99,99,99,99}; int memDay[10]= {99,99,99,99,99,99,99,99,99,99}; int memMonth[10]= {99,99,99,99,99,99,99,99,99,99}; int i = 0; void setup() { pinMode(knopset, INPUT); pinMode(knopmode, INPUT); pinMode(7, OUTPUT); //opening the door lcd.begin(20, 2); //set up the size of the LCD setTime(uur,minuut,seconde,dag,maand,jaar); //setting the starttime for the clock when it starts up } void loop(){ setklok(); //testing for times that must change digitalClockDisplay(); //displaying the clock delay(1000); getKeyCode(); //getting the iButton code testKeyCode(); //testing the iButton code modeklok(); } void setklok(){ //setting the clock modewaarde = digitalRead(knopmode); if (modewaarde == LOW){ //if the [mode]button is pusched lcd.clear(); lcd.print("tijd instellen"); lcd.setCursor(0, 1); //setting the hours lcd.print("uur: "); lcd.setCursor(9, 1); lcd.print(uur); lcd.print(" "); delay(knoptijd); modewaarde = digitalRead(knopmode); while (modewaarde == HIGH){ delay(knoptijd); setwaarde = digitalRead(knopset); if (setwaarde == LOW){ uur++; if (uur > 24) uur = 1; lcd.setCursor(9,1); lcd.print(uur); lcd.print(" "); } modewaarde = digitalRead(knopmode); } // setting the minutes lcd.setCursor(0, 1); lcd.print("minuut"); lcd.setCursor(9, 1); lcd.print(minuut); lcd.print(" "); delay(knoptijd); modewaarde = digitalRead(knopmode); while (modewaarde == HIGH){ delay(knoptijd); setwaarde = digitalRead(knopset); if (setwaarde == LOW){ minuut++; if (minuut > 59) minuut = 0; lcd.setCursor(9, 1); lcd.print(minuut); lcd.print(" "); } modewaarde = digitalRead(knopmode); } //setting the month lcd.setCursor(0, 1); lcd.print("maand "); lcd.setCursor(9, 1); lcd.print(maand); lcd.print(" "); delay(knoptijd); modewaarde = digitalRead(knopmode); while (modewaarde == HIGH){ delay(knoptijd); setwaarde = digitalRead(knopset); if (setwaarde == LOW){ maand++; if (maand > 12) maand = 1; lcd.setCursor(9, 1); lcd.print(maand); lcd.print(" "); } modewaarde = digitalRead(knopmode); } //setting the day lcd.setCursor(0, 1); lcd.print("dag "); lcd.setCursor(9, 1); lcd.print(dag); lcd.print(" "); delay(knoptijd); modewaarde = digitalRead(knopmode); while (modewaarde == HIGH){ delay(knoptijd); setwaarde = digitalRead(knopset); if (setwaarde == LOW){ dag++; if (maand == 1 || maand == 3 || maand == 5 || maand == 7 || maand == 8 || maand == 10 || maand == 12){ if (dag > 31) dag = 1; } if (maand == 4 || maand == 6 || maand == 9 || maand == 11){ if (dag > 30) dag = 1; } if (maand == 2){ if (dag > 28) dag = 1; } lcd.setCursor(9, 1); lcd.print(dag); lcd.print(" "); } modewaarde = digitalRead(knopmode); } setTime(uur,minuut,seconde,dag,maand,jaar); lcd.clear(); } } void digitalClockDisplay(){ //printing time and date lcd.setCursor(0,0); lcd.print(" "); lcd.setCursor(0,0); lcd.print(hour()); printDigits(minute()); lcd.print(" "); lcd.print(day()); lcd.print("/"); lcd.print(month()); lcd.print(" "); } void printDigits(int digits){ // utility function for digital clock display: prints preceding colon and leading 0 lcd.print(":"); if(digits < 10) lcd.print('0'); lcd.print(digits); } void getKeyCode(){ //getting the code from the iButton byte present = 0; byte data[12]; keyStatus=""; if ( !ds.search(addr)) { ds.reset_search(); return; } if ( OneWire::crc8( addr, 7) != addr[7]) { keyStatus="CRC invalid"; return; } if ( addr[0] != 0x01) { keyStatus="not DS1990A"; return; } keyStatus="ok"; ds.reset(); } void modeklok(){ //testing for the bottom-button ############################ setwaarde = digitalRead(knopset); if (setwaarde == LOW){ //if the [set]button is pusched lcd.clear(); lcd.print("Iem. buiten sluiten?"); lcd.setCursor(0, 1); //checking the memory lcd.print(geheugen[9]); lcd.print(" "); lcd.print(memHour[9]); lcd.print(":"); lcd.print(memMinute[9]); lcd.print(" "); lcd.print(memDay[9]); lcd.print("/"); lcd.print(memMonth[9]); lcd.print(" "); delay(knoptijd); setwaarde = digitalRead(knopset); i=8; while (modewaarde == HIGH){ if (setwaarde == LOW){ i--; lcd.setCursor(0,1); lcd.print(geheugen[i]); lcd.print(" "); lcd.print(memHour[i]); lcd.print(":"); lcd.print(memMinute[i]); lcd.print(" "); lcd.print(memDay[i]); lcd.print("/"); lcd.print(memMonth[i]); lcd.print(" "); delay(knoptijd); if(i==0){ lcd.clear(); lcd.setCursor(0, 1); //putting the last enter back on the screen lcd.print(geheugen[9]); lcd.print(" "); lcd.print(memHour[9]); lcd.print(":"); lcd.print(memMinute[9]); lcd.print(" "); lcd.print(memDay[9]); lcd.print("/"); lcd.print(memMonth[9]); lcd.print(" "); loop(); return; } } setwaarde = digitalRead(knopset); modewaarde = digitalRead(knopmode); } delay(knoptijd); i = 0; while(i == 0){ //keeping out iButton 1 lcd.setCursor(0,0); lcd.print("buitensluiten? ja->"); lcd.setCursor(0,1); lcd.print(name1); lcd.print(" nee->"); delay(knoptijd); //dubble waiting time here delay(knoptijd); modewaarde = digitalRead(knopmode); setwaarde = digitalRead(knopset); if (modewaarde == LOW){ uit1 = 0; lcd.setCursor(0,0); lcd.print("buitengesloten! "); //get out delay(1000); i=1; } if (setwaarde == LOW){ uit1 = 1; lcd.setCursor(0,0); lcd.print("mag er in "); //come in delay(1000); i=1; } } i = 0; while(i == 0){ //keeping out iButton 2 lcd.setCursor(0,0); lcd.print("buitensluiten? ja->"); lcd.setCursor(0,1); lcd.print(name2); lcd.print(" nee->"); delay(knoptijd); //dubble waiting time here delay(knoptijd); modewaarde = digitalRead(knopmode); setwaarde = digitalRead(knopset); if (modewaarde == LOW){ uit2 = 0; lcd.setCursor(0,0); lcd.print("buitengesloten! "); //get out delay(1000); i=1; } if (setwaarde == LOW){ uit2 = 1; lcd.setCursor(0,0); lcd.print("mag er in "); //come in delay(1000); i=1; } } i = 0; while(i == 0){ //keeping out iButton 3 lcd.setCursor(0,0); lcd.print("buitensluiten? ja->"); lcd.setCursor(0,1); lcd.print(name3); lcd.print(" nee->"); delay(knoptijd); //dubble waiting time here delay(knoptijd); modewaarde = digitalRead(knopmode); setwaarde = digitalRead(knopset); if (modewaarde == LOW){ uit3 = 0; lcd.setCursor(0,0); lcd.print("buitengesloten! "); //get out delay(1000); i=1; } if (setwaarde == LOW){ uit3 = 1; lcd.setCursor(0,0); lcd.print("mag er in "); //come in delay(1000); i=1; } } i = 0; while(i == 0){ //keeping out iButton 4 lcd.setCursor(0,0); lcd.print("buitensluiten? ja->"); lcd.setCursor(0,1); lcd.print(name4); lcd.print(" nee->"); delay(knoptijd); //dubble waiting time here delay(knoptijd); modewaarde = digitalRead(knopmode); setwaarde = digitalRead(knopset); if (modewaarde == LOW){ uit4 = 0; lcd.setCursor(0,0); lcd.print("buitengesloten! "); //get out delay(1000); i=1; } if (setwaarde == LOW){ uit4 = 1; lcd.setCursor(0,0); lcd.print("mag er in "); //come in delay(1000); i=1; } } i = 0; while(i == 0){ //keeping out iButton 5 lcd.setCursor(0,0); lcd.print("buitensluiten? ja->"); lcd.setCursor(0,1); lcd.print(name5); lcd.print(" nee->"); delay(knoptijd); //dubble waiting time here delay(knoptijd); modewaarde = digitalRead(knopmode); setwaarde = digitalRead(knopset); if (modewaarde == LOW){ uit5 = 0; lcd.setCursor(0,0); lcd.print("buitengesloten! "); //get out delay(1000); i=1; } if (setwaarde == LOW){ uit5 = 1; lcd.setCursor(0,0); lcd.print("mag er in "); //come in delay(1000); i=1; } } lcd.clear(); } } void testKeyCode(){ //check if the iButton presented is the right one lcd.setCursor(0, 1); if(keyStatus=="ok"){ if(addr[1] == but1[1] && addr[2] == but1[2] && addr[3] == but1[3] && addr[4] == but1[4] && uit1 == 1){welkeBut=1; name = name1;} if(addr[1] == but2[1] && addr[2] == but2[2] && addr[3] == but2[3] && addr[4] == but2[4] && uit2 == 1){welkeBut=2; name = name2;} if(addr[1] == but3[1] && addr[2] == but3[2] && addr[3] == but3[3] && addr[4] == but3[4] && uit3 == 1){welkeBut=3; name = name3;} if(addr[1] == but4[1] && addr[2] == but4[2] && addr[3] == but4[3] && addr[4] == but4[4] && uit4 == 1){welkeBut=4; name = name4;} if(addr[1] == but5[1] && addr[2] == but5[2] && addr[3] == but5[3] && addr[4] == but5[4] && uit5 == 1){welkeBut=5; name = name5;} if(welkeBut == 1 || welkeBut == 2 || welkeBut == 3 || welkeBut == 4 || welkeBut == 5){ lcd.print(name); lcd.print(" "); lcd.print(hour()); printDigits(minute()); lcd.print(" "); lcd.print(day()); lcd.print("/"); lcd.print(month()); lcd.print(" "); digitalWrite(7, HIGH); delay(500); digitalWrite(7, LOW); bewaren(); //put last visit in memory } if(welkeBut != 1 && welkeBut != 2 && welkeBut != 3 && welkeBut != 4 && welkeBut != 5){ digitalWrite(7, LOW); lcd.print(" "); lcd.setCursor(0, 1); byte i; for( i = 5; i >0; i--) { lcd.print(":"); lcd.print(addr[i], DEC); } delay(1000); lcd.setCursor(0, 1); lcd.print(" "); } } else { welkeBut = 0; if (keyStatus!="") { lcd.setCursor(0, 1); lcd.print(keyStatus); delay(1000); lcd.setCursor(0, 1); lcd.print(" "); } } } void bewaren(){ //put last visit in memory geheugen[0] = geheugen[1]; geheugen[1] = geheugen[2]; geheugen[2] = geheugen[3]; geheugen[3] = geheugen[4]; geheugen[4] = geheugen[5]; //every visit is moving one memory-location down geheugen[5] = geheugen[6]; geheugen[6] = geheugen[7]; geheugen[7] = geheugen[8]; geheugen[8] = geheugen[9]; geheugen[9] = name; //the newest visit is added memHour[0] = memHour[1]; //the same for the hours memHour[1] = memHour[2]; memHour[2] = memHour[3]; memHour[3] = memHour[4]; memHour[4] = memHour[5]; memHour[5] = memHour[6]; memHour[6] = memHour[7]; memHour[7] = memHour[8]; memHour[8] = memHour[9]; memHour[9] = hour(); memMinute[0] = memMinute[1]; memMinute[1] = memMinute[2]; memMinute[2] = memMinute[3]; memMinute[3] = memMinute[4]; memMinute[4] = memMinute[5]; memMinute[5] = memMinute[6]; memMinute[6] = memMinute[7]; memMinute[7] = memMinute[8]; memMinute[8] = memMinute[9]; memMinute[9] = minute(); memDay[0] = memDay[1]; memDay[1] = memDay[2]; memDay[2] = memDay[3]; memDay[3] = memDay[4]; memDay[4] = memDay[5]; memDay[5] = memDay[6]; memDay[6] = memDay[7]; memDay[7] = memDay[8]; memDay[8] = memDay[9]; memDay[9] = day(); memMonth[0] = memMonth[1]; memMonth[1] = memMonth[2]; memMonth[2] = memMonth[3]; memMonth[3] = memMonth[4]; memMonth[4] = memMonth[5]; memMonth[5] = memMonth[6]; memMonth[6] = memMonth[7]; memMonth[7] = memMonth[8]; memMonth[8] = memMonth[9]; memMonth[9] = month(); }