Paso 10: código
Estaba corto de tiempo y lo mucho de mi código se encuentra mal escrito y construido. Voy a publicar un código más adelante que más fácilmente se modifica, pero no será capaz de probar con el cantinero, como ha sido desmontado para piezas.
En general, el código tiene entrado desde el teclado, evalúa la selección utilizando instrucciones switch/case y luego suministra una bebida. Cada bebida está escrito como una función. Una copa es vertida por el relé de cierre y encender las bombas por una cantidad específica de tiempo. Controlado el tiempo de que los relés se cerraron mediante la función delay() en lugar de utilizar temporizadores. Esto hace extraño a escribir cuando los ingredientes estén en diferentes cantidades de tiempo y difícil de modificar y ampliar el código. El nuevo código reemplaza delay() con temporizadores.
La biblioteca de I2C y la información se pueden encontrar aquí: http://arduino-info.wikispaces.com/LCD-Blue-I2C
#include // Comes with Arduino IDE#include LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C addressint keys[] ={ //Stores total keypad input 1, 2, 3, 10, 4, 5, 6, 11, 7, 8, 9, 12, -3,0, -2, 14}; //"123A456B789C*0#D"; int key; //Stores most recent key pressed boolean key_lockout=false; int order[4]; int value=0; //Initialize const int vodka=3; //Based on 6v clear pump, 13.3 sec/oz (20 sec/1.5 oz) const int gin=4; //Based on 12v black pumps, 25.3 sec/oz (38 sec/1.5 oz) const int whiskey=5; const int tripleSec=6; const int tequila=7; const int rum=8; const int water=9; const int simpleSyrup=10;void setup(){ Serial.begin(9600); lcd.begin(16,2); pinMode(vodka, OUTPUT); pinMode(gin, OUTPUT); pinMode(whiskey, OUTPUT); pinMode(tripleSec, OUTPUT); pinMode(tequila, OUTPUT); pinMode(rum, OUTPUT); pinMode(simpleSyrup, OUTPUT); pinMode(water, OUTPUT); digitalWrite(vodka, HIGH); digitalWrite(gin, HIGH); digitalWrite(whiskey, HIGH); digitalWrite(tripleSec, HIGH); digitalWrite(tequila, HIGH); digitalWrite(rum, HIGH); digitalWrite(simpleSyrup, HIGH); digitalWrite(water, HIGH); // ------- 3 blinks of backlight ------------- for(int i = 0; i< 3; i++) { lcd.backlight(); delay(250); lcd.noBacklight(); delay(250); } lcd.backlight(); // finish with backlight on }void loop(){ Beginning: { //-------- Write characters on the display ------------------ // NOTE: Cursor Position: (CHAR, LINE) start at 0 lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Enter your order"); delay(500); lcd.setCursor(0,1); lcd.print(" *-Clr, #-Enter"); delay(1000); //----------------------------------------------------------- value=0; for (int x=0; x<4; x++){ key=getKeypad(); //Get key pressed if(key==-1){ //If valid key not pressed restart iteration x=x-1; } else{ if(key!=14 && key!=12){ //If not CLEAR or ENTER value = (10*(value)) + (keys[key]); delay(10); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Item #"); delay(10); lcd.setCursor(6,0); lcd.print(value); delay(500); } else if(key==14){ //If ENTER, exit x=4; } else if (key==12){ //If CLEAR, restart x=-1; } } } lcd.clear(); lcd.setCursor(0,0); lcd.print(" Press # to"); delay(10); lcd.setCursor(0,1); lcd.print("Confirm drink"); delay(10); lcd.setCursor(14,1); lcd.print(value); do{ key=getKeypad(); } while(key!=12 && key!=14); if(key==12){ //Restart ordering process goto Beginning; //Return to the beginning of loop() } else if(key==14){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" Confirmed"); delay(1000); switch (value) { case 1: longIslandIcedTea(); break; case 2: jackAndCoke(); break; case 3: rumAndCoke(); break; case 4: capeCod(); break; case 5: cosmopolitan(); break; case 6: kamikazee(); break; case 7: screwdriver; break; case 8: highball(); break; case 9: gt(); break; case 10: vodkaTonic(); break; case 11: margarita(); break; case 12: seaBreeze(); break; } delay(5); // delay in between reads for stability } } }//--------Functions----------- int getKeypad(){ //Returns which key is pressed int ret=-1; boolean reset_lockout=false; if(analogRead(A0)<120) key_lockout=false; else if(!key_lockout){ delay(100); ret=15.5-(log((analogRead(A0)-183.9)/58.24)/0.1623);//+0.5; key_lockout=true; } return ret; }// Menu //Long Island Iced Tea int longIslandIcedTea(){ digitalWrite(vodka, LOW); delay(80); digitalWrite(gin, LOW); delay(80); digitalWrite(tripleSec, LOW); delay(80); //Serial.println("In the matrix"); digitalWrite(tequila, LOW); delay(80); digitalWrite(rum, LOW); delay(80); digitalWrite(water, LOW); delay(6600); digitalWrite(vodka, HIGH); delay(6400); digitalWrite(water, HIGH); digitalWrite(gin, HIGH); digitalWrite(tripleSec, HIGH); digitalWrite(tequila, HIGH); digitalWrite(rum, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add 1oz Sour Mix"); delay(10); lcd.setCursor(0,1); lcd.print(" then MIX"); delay(5000); lcd.clear(); lcd.print("Add ice and "); delay(10); lcd.setCursor(0,1); lcd.print("top with coke"); delay(3000); } }//Jack and Coke int jackAndCoke(){ //2 oz of whiskey Serial.println("Jack and Coke"); digitalWrite(whiskey, LOW); delay(10); digitalWrite(water, LOW); delay(4500); digitalWrite(water, HIGH); delay(33500); digitalWrite(whiskey, HIGH); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add ice and 2-5"); delay(10); lcd.setCursor(0,1); lcd.print("ounces of Coke"); delay(8000); }//Rum and Coke int rumAndCoke(){ //2 oz of rum Serial.println("Rum and Coke"); digitalWrite(rum, LOW); delay(10); digitalWrite(water, LOW); delay(4500); digitalWrite(water, HIGH); delay(33500); digitalWrite(rum, HIGH); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add ice and 2-5"); delay(10); lcd.setCursor(0,1); lcd.print("ounces of Coke"); delay(8000); }//Cape Cod int capeCod(){ //2 oz of vodka, 3 oz cranberry juice, lime wedge Serial.println("Cape Cod"); digitalWrite(vodka, LOW); delay(10); digitalWrite(water, LOW); delay(4500); digitalWrite(water, HIGH); delay(15500); digitalWrite(vodka, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add ice & 2-3 oz"); delay(10); lcd.setCursor(0,1); lcd.print("Cranberry Juice-"); delay(3000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("and a lime wedge"); delay(3000); } }//Bay Breeze int bayBreeze(){ //2 oz of vodka, 5 oz cranberry juice, 2 oz pineapple juice (or equal parts ~2.5 oz each), lime wedge Serial.println("Bay Breeze"); digitalWrite(vodka, LOW); delay(10); digitalWrite(water, LOW); delay(4500); digitalWrite(water, HIGH); delay(15500); digitalWrite(vodka, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add ice & 4-5 oz"); delay(10); lcd.setCursor(0,1); lcd.print("Cranberry Juice"); delay(4000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("and 2oz of"); lcd.setCursor(0,1); lcd.print("Pineapple Juice"); delay(3000); } }//Cosmopolitan int cosmopolitan(){ //1 1/2 ounces vodka or citrus vodka, 1 ounce Cointreau orange liqueur, 1/2 ounce fresh lime juice, 1/4 ounce cranberry juice Serial.println("Cosmopolitan"); digitalWrite(tripleSec, LOW); delay(10); digitalWrite(vodka, LOW); delay(10); digitalWrite(water, LOW); delay(13000); digitalWrite(water, HIGH); delay(7000); digitalWrite(vodka, HIGH); delay(5323); digitalWrite(tripleSec, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add 1/2 oz lime"); delay(10); lcd.setCursor(0,1); lcd.print(" Juice and MIX"); delay(4000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" Top with"); lcd.setCursor(0,1); lcd.print("Cranberry Juice"); delay(3000); } }//Kamikazee int kamikazee(){ //1 1/2 -1 ounces vodka, 1 ounce lime juice, 1 ounce triple sec, Lime wedge for garnish //shake Serial.println("Kamikazee"); digitalWrite(tripleSec, LOW); delay(10); digitalWrite(vodka, LOW); delay(10); digitalWrite(water, LOW); delay(13000); digitalWrite(water, HIGH); delay(7000); digitalWrite(vodka, HIGH); delay(5323); digitalWrite(tripleSec, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add 1 oz Lime"); delay(10); lcd.setCursor(0,1); lcd.print(" Juice and MIX"); delay(4000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" Add Ice"); lcd.setCursor(0,1); lcd.print("and lime wedge"); delay(3000); } }//Screwdriver int screwdriver(){ //1 1/2 -1 ounces vodka, 5 oz orange juice Serial.println("Screwdriver"); digitalWrite(vodka, LOW); delay(20000); digitalWrite(vodka, HIGH); for (int x=0; x<2; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add Ice and ~5"); delay(10); lcd.setCursor(0,1); lcd.print("oz Orange Juice"); delay(3000); } }//Highball int highball(){ //1.5 ounces whiskey, ginger ale Serial.println("Highball"); digitalWrite(whiskey, LOW); delay(38000); digitalWrite(whiskey, HIGH); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" Add Ice and"); delay(10); lcd.setCursor(0,1); lcd.print(" Ginger Ale"); delay(8000); }//Gin and Tonic int gt(){ //1.5 ounces gin, 2.25 tonic or 2:3, 1/4 oz lime juice Serial.println("Gin and Tonic"); digitalWrite(gin, LOW); delay(38000); digitalWrite(gin, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add Ice, 2-5 oz"); delay(10); lcd.setCursor(0,1); lcd.print("of Tonic and..."); delay(3000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" 1/4 oz"); lcd.setCursor(0,1); lcd.print(" Lime Juice"); delay(3000); } }//Vodka Tonic int vodkaTonic(){ //1.5 ounces vodka, 3-4.5 tonic, 1/4 oz lime juice Serial.println("Vodka Tonic"); digitalWrite(vodka, LOW); delay(20000); digitalWrite(vodka, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add Ice, 2-5 oz"); delay(10); lcd.setCursor(0,1); lcd.print("of Tonic and..."); delay(3000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" 1/4 oz"); lcd.setCursor(0,1); lcd.print(" Lime Juice"); delay(3000); } }//Margarita int margarita(){ digitalWrite(tripleSec, LOW); delay(10); digitalWrite(tequila, LOW); delay(10); digitalWrite(water, LOW); delay(13000); digitalWrite(water, HIGH); delay(12700); digitalWrite(tripleSec, HIGH); delay(12870); digitalWrite(tequila, HIGH); for (int x=0; x<3; x++){ lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print("Add 1/2 oz of"); delay(10); lcd.setCursor(0,1); lcd.print("Lime Juice &..."); delay(3000); lcd.clear(); lcd.setCursor(0,0); //Start at character 4 on line 0 lcd.print(" MIX"); lcd.setCursor(0,1); lcd.print(" then add ice "); delay(4000); } }//Sea Breeze int seaBreeze(){ //1.35 Vodka, 4 Cranberry juice, 1 Grapefruit juice Serial.println("Sea Breeze"); digitalWrite(vodka, LOW); delay(18000); digitalWrite(vodka, HIGH); }