Created
December 14, 2011 01:11
-
-
Save onursenture/1474746 to your computer and use it in GitHub Desktop.
MacQuick Vending Software
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* MacQuick Software Version 0.13 | |
now it CAN DO something. really. :) | |
created december 2011 | |
by vfood software engineering team | |
version notes | |
version 0.14 | |
- keypad inefficiency has resolved | |
*/ | |
// include the library code | |
#include <LiquidCrystal.h> | |
#define STEP 200 | |
int DONE = 001; int ING1 = 010; int ING2 = 011; int ING3 = 100; int ING4 = 101; int ING5 = 110; int CLR = 111; | |
int ingredientCounter = 0; | |
int ing_amount[] = {0, 0, 0, 0, 0}; | |
int ingredient[] = {1000, 1000, 1000, 1000, 1000}; // will be changed | |
int motorPins[] = {7, 8, 9, 10, 1, 13}; | |
//initialize the library with the numbers of the interface pins | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
void setup() { | |
// setup the pins here | |
pinMode(6, INPUT); // keypad serial input | |
pinMode(7, OUTPUT); // motor 1 driver output | |
pinMode(8, OUTPUT); // motor 2 driver output | |
pinMode(9, OUTPUT); // motor 3 driver output | |
pinMode(10, OUTPUT); // motor 4 driver output | |
pinMode(1, OUTPUT); // motor 5 driver output | |
pinMode(13, OUTPUT); // motor 6 driver output | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16,4); | |
lcd.clear(); | |
} | |
void loop() { | |
// send "ready to lcd" | |
lcd.print("hello. macquick is ready to work"); | |
// wait signal from bill validator and take inputs | |
take_inputs(700); | |
// check plate | |
wait_until_bowlis_there(700); | |
// pasta & ingredient filling, sending signal to motors | |
fill_ingredients(10); | |
} | |
// modules | |
// take input module | |
// takes analog threshold value as an input | |
void take_inputs(int analog_threshold){ | |
int bill_validator = analogRead(A0); | |
if (bill_validator > analog_threshold) | |
{ | |
// send "choose ingredients" message to LCD | |
lcd.print("please choose what you want to add to your pasta"); | |
int doneFlag = 0; | |
// here there is some inefficiency since we need to read keypad input consecutively, | |
while(doneFlag != 1) | |
{ | |
int keypad = 0; | |
// wait until keypad signal has come | |
while(keypad == 0) | |
keypad = digitalRead(6); | |
for(int i = 0; i <= 5; i++) | |
{ | |
ingredientCounter = ingredientCounter + ing_amount[i]; | |
} | |
if((keypad == DONE) || (ingredientCounter == 5)) | |
{ | |
doneFlag = 1; | |
lcd.print("okkey! our dwarfs preparing your meal"); | |
delay(5000); | |
} | |
else if(keypad = ING1) | |
{ | |
if(ingredient[0] > 0) | |
{ | |
ing_amount[0]++; | |
} | |
else | |
{ | |
lcd.print("not enough ingredient 1"); | |
delay(5000); | |
} | |
} | |
else if(keypad = ING2) | |
{ | |
if(ingredient[1] > 0) | |
{ | |
ing_amount[1]++; | |
} | |
else | |
{ | |
lcd.print("not enough ingredient 2"); | |
delay(5000); | |
} | |
} | |
else if(keypad = ING3) | |
{ | |
if(ingredient[2] > 0) | |
{ | |
ing_amount[2]++; | |
} | |
else | |
{ | |
lcd.print("not enough ingredient 3"); | |
delay(5000); | |
} | |
} | |
else if(keypad = ING4) | |
{ | |
if(ingredient[3] > 0) | |
{ | |
ing_amount[3]++; | |
} | |
else | |
{ | |
lcd.print("not enough ingredient 4"); | |
delay(5000); | |
} | |
} | |
else if(keypad = ING5) | |
{ | |
if(ingredient[4] > 0) | |
{ | |
ing_amount[4]++; | |
} | |
else | |
{ | |
lcd.print("not enough ingredient 5"); | |
delay(5000); | |
} | |
} | |
else if(keypad = CLR) | |
{ | |
// clear all ingredients | |
for(int i = 0; i <= 5; i++) | |
{ | |
ing_amount[i] = 0; | |
} | |
} | |
else | |
{ | |
doneFlag = 0; | |
} | |
} | |
} | |
} | |
// bowl check | |
// takes analog threshold value as an input | |
void wait_until_bowlis_there(int analog_threshold){ | |
while(analogRead(A1) < analog_threshold) | |
{ | |
lcd.print("place plate please!"); | |
delay(100); | |
} | |
} | |
// ingredient filling | |
// takes stepper delay as an input | |
void fill_ingredients(int stepper_delay){ | |
for(int i = 0; i < STEP; i++) | |
{ | |
digitalWrite(motorPins[0], HIGH); | |
delay(stepper_delay); | |
} | |
while(ingredientCounter!=0) | |
{ | |
for(int i = 0; i <= 5; i++) | |
{ | |
if(ing_amount[i] != 0) | |
{ | |
for(int k = 0; k < STEP; k++) | |
{ | |
digitalWrite(motorPins[i+1], HIGH); | |
delay(stepper_delay); | |
} | |
ing_amount[i]--; | |
ingredientCounter--; | |
} | |
} | |
} | |
lcd.print("you can take your pasta! bon appetit!"); | |
delay(10000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment