Code
How it works:
The egg machine parces data from Weather.com to find whether it is sunny or cloudy that day, then sends that information through Processing to the serial port. Arduino then reads this and does one of two things. makes scrambled or sunny side up eggs. This particular piece of code is what was in the Arduino during the presentation. As we where having server issues, the machine only made scrambled egs,though it has the functions to do either. HERE is the link to the PHP page that has the parsed weather.
Code:
#include <TimedAction.h>
#include <Servo.h>
//************************************************************************/
// The egg Machine.
//************************************************************************/
///////////////////VARIABLES///////////////////////////////////////////////
//-------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
/* Booleans notifying about which step in the process has been reached. */
boolean trigger = false; // turn the machine on and off based on egg sensor.
boolean step_one = false; // egg has been placed, trigger solenoid.
boolean step_two = false; // egg is coming down the tube, trigger hotplate and potentially, spatula.
boolean step_three = false; // egg is cooked. trigger tilt mechanism to maxiumum capacity.
boolean step_four = false; // egg is on plate. Activate ready noise.
boolean punch = true; // punchin
boolean once = true;
///////////////////////
/*/Countin the eggs */
int currentEgg = 0;
int lastEgg;
int eggCount = 0;
///////////////////////
/*includes */
///////////////////////
/* General Variables */
// The egg counter determines how long the egg should cook. If higher than 1, the
// egg cooks longer, because the plate is, theoretically, already hot.
int egg_counter = 0;
int trigger_delay = 1000; // set the delay after which the mechanics start (millis)
// If the following variable is true, the machine cooks the eggs sunny side up. Otherwise,
// if makes them scrambled. The information concerning this variable is grabbed from
// the internet, using php and processing.
boolean sunny = true;
int cooking_time_long = 120000; // cooking time if egg_counter == 0;
int cooking_time_short = 80000; // cooking time if egg_counter > 0;
int liftTime = 2000; // time (in millis) during which the lift motor has to be active to pull up the pan.
int oldTime; // Time defined in millis to be checked back on
int newTime; // New time to be compared to "oldTime"
boolean timeSwitch = false;
/////////////////////////
/* Flip Flap (spatula) */
int flippyPos = 0; // angle by which the spatula needs to move back and forth to scramble eggs.
/////////////////////////
// I/O //////////////
/////////////////////////
/////////////////////////
/* Trigger Incoming */
int eggTrigger = 11; // pin used as digital input for egg recognition trigger
int eggTriggerRead = 10; // pin to read from the egg trigger
boolean eggness =false;
////////////
/* MOTORS */
int gearMotorBackward = 3; // Pin used as output for lifting motor
int gearMotorForward = 7;
Servo spatuServo;
/////////////
/*Hot Plate*/
int hotPlate = 5; //pin to trigger hotplate
////////////
/*Solenoid*/
int solenoid = 6; //pin to trigger solenoid
//TIMED ACTIONS//
TimedAction DCup_scrambulate = TimedAction(10,DCup);
TimedAction DCdown_scrambulate = TimedAction(10,DCdown);
/////////////////SETUP/////////////////////////////////////////////////////
//-------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////
void setup(){
pinMode(eggTrigger,OUTPUT); // setup a pin to act as input for the egg trigger
pinMode(eggTriggerRead,INPUT);
pinMode(gearMotorForward,OUTPUT); // setup a pin to switch on the "lift" motor
pinMode(gearMotorBackward,OUTPUT); // setup a pin to switch on the "lift" motor
pinMode(hotPlate,OUTPUT); // setup a pin to turn on the hotplate
pinMode(solenoid,OUTPUT); // setup a pin to switch on the solenoid
spatuServo.attach(4); // Spatulate pin number 4!
Serial.begin(9600);
digitalWrite(eggTriggerRead, LOW);
}
/////////////////FUNCTIONS////////////////////////////////////////////////
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
//DC motor functions
void DCup(){
digitalWrite(gearMotorForward,HIGH);
digitalWrite(gearMotorBackward,LOW);
}
void DCdown(){
digitalWrite(gearMotorForward,LOW);
digitalWrite(gearMotorBackward,HIGH);
}
void DCstop(){
digitalWrite(gearMotorForward,HIGH);
digitalWrite(gearMotorBackward,HIGH);
}
// function to punch the egg. why is this a function?
void punchEgg(){
digitalWrite(solenoid,LOW);
digitalWrite(solenoid,HIGH);
}
// function for scrambulation of the eggs, the half
// that lifts the pan and lowers it while the spatulate
// function is running
void spatulate(){
for(flippyPos = 80; flippyPos>=0; flippyPos--) // goes from 180 degrees to 0 degrees
{
spatuServo.write(flippyPos);
}
delay(500);
for(flippyPos = 0; flippyPos < 80; flippyPos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
spatuServo.write(flippyPos); // tell servo to go to position in variable 'flippyPos'
}
delay(500);
}
// function to make sure spatulation occurs
void scrambulate(){ // tell servo to go to position in variable 'flippyPos'
for(int c=0; c<3;c++){
for(int i=0; i<5;i++){
spatulate();
Serial.println(i);
}
//DCup_scrambulate.check();
for(int i=0; i<400; i++){
DCup();
}
for(int i=0; i<=5;i++){
spatulate();
Serial.println(i);
}
for(int i=0; i<400; i++){
DCdown();
}
Serial.println(c);
}
DCstop();
}
void eggRemoval () {
flippyPos = 0;
spatuServo.write(flippyPos);
delay(1000);
for(int i=0;i<2000;i++){
DCup();
}
delay(6000);
for(flippyPos=0;flippyPos<90;flippyPos++){
spatuServo.write(flippyPos);
}
delay(8000);
for(flippyPos=90;flippyPos>=55;flippyPos--){
spatuServo.write(flippyPos);
}
delay(8000);
DCstop();
for(flippyPos=55;flippyPos<90;flippyPos++){
spatuServo.write(flippyPos);
}
delay(6500);
for(int i=0;i<1000;i++){
DCdown();
}
delay(21000);
DCstop();
spatuServo.write(80);
}
/////////////////MAIN/////////////////////////////////////////////////////
//------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////
/////////////////
/*Timed actions*/
//TimedAction liftPan = TimedAction(3000,motorLift);
void loop(){
spatuServo.write(0);
digitalWrite(solenoid, HIGH);
digitalWrite(eggTrigger,HIGH);
if(digitalRead(eggTriggerRead) == HIGH){
eggness = true;
}
if(eggness == true){
delay(2000);
digitalWrite(solenoid, LOW);
delay(2000);
scrambulate();
delay(40000);
eggRemoval();
delay(30000);
eggness = false;
}
}



