Created
December 25, 2011 22:14
-
-
Save onursenture/1519823 to your computer and use it in GitHub Desktop.
MacQuick Prototype Demo 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 Demo Software | |
created december 2011 ~revision 9: 2 may 2012 20:30 | |
by vfood software engineering team | |
*/ | |
//LCD D(12,11,5,4,3,2) | |
//Motors D(9,10,13) | |
//Main Motor Direction D(0) | |
//Keypad D(1,6,7,8) | |
//Dollar Analog | |
#define STEP_PIN HIGH | |
#include <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
int keypad_1 = 1; | |
int keypad_2 = 1; | |
int keypad_3 = 1; | |
int keypad_4 = 1; | |
int bill_validator = 0; | |
int ingredientCount = 0; | |
boolean ingredient1 = false; | |
boolean ingredient2 = false; | |
boolean gimmeFlag = false; | |
void setup(){ | |
// keypad specifications | |
// keypad_1 = 1 --> ingredient 1 selection | |
// keypad_2 = 6 --> ingredient 2 selection | |
// keypad_3 = 7 --> give me my macaroni button | |
// keypad 4 = 8 --> clear button | |
pinMode(1, INPUT); // keypad input 1 | |
pinMode(6, INPUT); // keypad input 2 | |
pinMode(7, INPUT); // keypad input 3 | |
pinMode(8, INPUT); // keypad input 4 | |
pinMode(13, OUTPUT); // ingredient 2 motor output (step) | |
pinMode(10, OUTPUT); // ingredient 1 motor output (step) | |
pinMode(9, OUTPUT); // main motor driver output (step) | |
pinMode(0, OUTPUT); // main motor driver output (direction) | |
lcd.begin(20,4); | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
} | |
void loop(){ | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("MacQuick is ready to serve!"); | |
take_inputs(); | |
fill_ingredients(ingredient1, ingredient2); | |
ingredient1 = false; | |
ingredient2 = false; | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
lcd.print("Your pasta is ready! Bon Appetit!"); | |
delay(3000); | |
} | |
void take_inputs(){ | |
bill_validator = analogRead(A0); | |
// bill validation control: wait until dolar signal comes | |
while(bill_validator >700) //ÇALIŞMASI İÇİN OLMASI GEREKENİN TAM TESİNE ÇEVİRDİM | |
{ | |
keypad_1 = digitalRead(1); | |
keypad_2 = digitalRead(6); | |
keypad_3 = digitalRead(7); | |
if(keypad_1 == 0 || keypad_2 == 0 || keypad_3 == 0){ | |
delay(1000); // will be deleted | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("Not sufficient money. "); // spaces are necessary. do not delete. | |
lcd.setCursor(0,0); | |
keypad_1 = 1; | |
keypad_2 = 1; | |
keypad_3 = 1; | |
delay(1500); | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("MacQuick is ready to serve!"); | |
} | |
keypad_1 = 1; | |
keypad_2 = 1; | |
keypad_3 = 1; | |
bill_validator = analogRead(A0); | |
} | |
// bill validation reset | |
bill_validator = analogRead(A0); | |
lcd.clear(); | |
lcd.setCursor(0, 0); | |
ingredientCount = 0; | |
// wait until give my pasta button has pressed or two ingredient selected | |
while(gimmeFlag==false){ | |
keypad_1 = 1; | |
keypad_2 = 1; | |
keypad_3 = 1; | |
keypad_4 = 1; | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("Choose ingredients."); | |
//wait while there is no input from ingredient and gimme buttons | |
while (keypad_1 == 1 && keypad_2 == 1 && keypad_3 == 1 && keypad_4 == 1){ | |
keypad_1 = digitalRead(1); | |
keypad_2 = digitalRead(6); | |
keypad_3 = digitalRead(7); | |
keypad_4 = digitalRead(8); | |
} //exit the wait loop when the input has come | |
//ingredient 1 button pressed | |
if(keypad_1 == 0){ | |
gimmeFlag = false; | |
ingredient1 = true; | |
ingredientCount++; | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("OK! ingred 1"); | |
delay(1000); | |
} | |
//ingredient 2 button pressed | |
else if(keypad_2 == 0){ | |
gimmeFlag = false; | |
ingredient2= true; | |
ingredientCount++; | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("OK! ingred 2"); | |
delay(1000); | |
} | |
//gimme button pressed | |
else if(keypad_3 == 0) { | |
gimmeFlag = true; | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("OK! give me button pressed"); | |
delay(1000); | |
} | |
//cancel button pressed | |
else{ //resets the ingredients | |
ingredient1 = false; | |
ingredient2 = false; | |
ingredientCount = 0; | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("OK! cancelled"); | |
delay(1000); | |
} | |
//check whether ingredient cap is reached or not | |
if(ingredientCount==2) | |
{ | |
gimmeFlag = true; | |
} | |
} | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
lcd.print("Patience. Preparing."); | |
delay(1000); | |
// reset variables | |
bill_validator = 0; | |
ingredientCount = 0; | |
//ingredient1 = false; | |
//ingredient2 = false; | |
gimmeFlag = false; | |
keypad_1 = 1; | |
keypad_2 = 1; | |
keypad_3 = 1; | |
keypad_4 = 1; | |
// wait | |
delay(2000); | |
} | |
void fill_ingredients(boolean ing1, boolean ing2){ | |
//ing1 comes here with true value if ingredient 1 is selected | |
//ing2 comes here with true value if ingredient 2 is selected | |
if(ing1==true){ | |
rotateDeg(45.7142858, .03, 10); //send signal to ingredient 1 motor | |
delay(1000); | |
rotateDeg(45.7142858, .03, 10); //send signal to ingredient 1 motor | |
} | |
delay(250); | |
if(ing2==true){ | |
rotateDeg(45.7142858, .03, 13); //send signal to ingredient 2 motor | |
delay(1000); | |
rotateDeg(45.7142858, .03, 13); //send signal to ingredient 2 motor | |
} | |
delay(250); | |
digitalWrite(0,LOW); | |
rotateDeg(45.7142858, .03, 9); //send signal to main motor | |
delay(1000); | |
digitalWrite(0,HIGH); | |
rotateDeg(45.7142858, .03, 9); //send signal to main motor | |
delay(1000); | |
lcd.clear(); | |
lcd.setCursor(0,0); | |
} | |
void rotate(int steps, float speed){ | |
//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger | |
int dir = (steps > 0)? HIGH:LOW; | |
steps = abs(steps); | |
//digitalWrite(DIR_PIN,dir); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(STEP_PIN, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(STEP_PIN, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} | |
void rotateDeg(float deg, float speed, int motorNumber){ | |
//rotate a specific number of degrees (negitive for reverse movement) | |
//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger | |
int dir = (deg > 0)? HIGH:LOW; | |
//digitalWrite(DIR_PIN,dir); | |
int steps = abs(deg)*(1/0.225); | |
float usDelay = (1/speed) * 70; | |
for(int i=0; i < steps; i++){ | |
digitalWrite(motorNumber, HIGH); | |
delayMicroseconds(usDelay); | |
digitalWrite(motorNumber, LOW); | |
delayMicroseconds(usDelay); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment