Programming

 

This is the code used to operate our system. It prompts the user for the amount of each topping that they would like, and then asks them to press the stop button to advance to the next option. After progressing through each topping, the main body excecutes, and the table positions to each station, and the toppings are dispensed.

 

/* ICDM.c */

/* Lexyne McNealy
Tony Swanson
Drew Witte */

/* This is the control program for the Ice Cream Dream Machine */
/* created by Team 11 - The Triple Scoops for ME 333 Mechatronics */
/* Winter Quarter, 2003. The program provides functions that control */
/* the turntable, each topping station, and the actuators of the system. */
/* (11) */

int i, j; /* counter variables */
int TRUE = 1, fON = 3000, fOFF = 3700, sON = 1500, sOFF = 3300;


void turntable(int station)
{
if(station == 0) /* turntable at home (pin 7) */
{
while(digital(7) != 0)
fd(0); /* turns motor CCW */
off(0); /* turns motor off */
}

if(station == 1) /* turntable at dry toppings(pin 8) */
{
while(digital(8) != 0)
fd(0); /* turns motor CCW */
off(0); /* turns motor off */
}

if(station == 2) /* turntable at chocolate (pin 11) */
{
while(digital(11) != 0)
fd(0); /* turns motor CCW */ /* (37) */
off(0); /* turns motor off */
}


if(station == 3) /* turntable at whipped cream station (pin 12) */
{
while(digital(12) != 0)
fd(0); /* turns motor CCW */
off(0); /* turns motor off */
}
}

void motor_choc(int i, int station)
{
/* positions turntable under the chocolate station */

int k = i;
for(i=0; i<k; i++){
fd(1);
sleep(1.5);
bk(1);
sleep(1.5);
}
off(1);
} /* (62) */

void servo_MM(int i, int station) /* servo_a7 */
{
int k = i;

servo_a7_init(1);

for(i=0; i<k; i++){
servo_a7_pulse = sON;
sleep(2.5);
servo_a7_pulse = sOFF;
sleep(1.0);
}
servo_a7_init(0);
}

void servo_sprinkles(int j, int station) /* servo a5 */
{
int k = j;

servo_a5_init(1);
sleep(2.0);
for(j=0; j<k; j++){
servo_a5_pulse = fON;
sleep(2.0);
servo_a5_pulse = fOFF;
sleep(1.0);
}
servo_a5_init(0);
}

void solo_wc(int i, int station)
{
int k = i;
/* (97) */
for(i=0; i<k; i++){
poke(0x1009, 0x3c);
poke(0x1008, 00100000);
sleep(0.5);
poke(0x1008, 00000000);
sleep(0.5);
} /* (104) */
}

void instructions()
{
printf("\n Welcome to...");
sleep(1.0);
printf("\nThe Ice Cream Dream Machine!");
sleep(2.0);
printf("\nPress start to begin");

start_press();

printf("\nDirections");
sleep(2.5);
printf("\nYou have 4 options..."); /* (119) */
sleep(2.5);
printf("\nChocolate syrup, 2 dry toppings, ");
sleep(2.5);
printf("\nand whipped cream.");
sleep(2.5);
printf("\nPress button 1, 2, or 3");
sleep(2.5);
printf("\n when prompted ");
sleep(2.5);
printf("\nfor the serving amount.");
sleep(2.5);
printf("\nPress stop for the next option");
sleep(2.5); /* (132) */
}

void chocolate()
{
turntable(2);
sleep(2.0);
printf("\nChocolate syrup? (1, 2, or 3)");
sleep(5.0);
printf("\nPress stop for next option");

if(digital(15) == 1) /* button 1 */ /* (143) */
motor_choc(1, 2);
if(digital(14) == 1) /* button 2 */
motor_choc(2, 2);
if(digital(13) == 1) /* button 3 */
motor_choc(3, 2);

stop_press();
} /* (151) */

void drymix()
{
turntable(1);
sleep(2.0);
printf("\n Peanuts? (Press 1, 2, or 3)");
sleep(5.0);
printf("\nPress stop for next option");

if(digital(15) == 1) /* (161) */
servo_MM(1, 1);
if(digital(14) == 1)
servo_MM(2, 1);
if(digital(13) == 1)
servo_MM(3, 1);

stop_press();

printf("\nSprinkles? (1, 2, or 3)");
sleep(5.0);
printf("\nPress stop for next option");

if(digital(15) == 1) /* (174) */
servo_sprinkles(1, 1);
if(digital(14) == 1)
servo_sprinkles(2, 1);
if(digital(13) == 1)
servo_sprinkles(3, 1);

stop_press();
}

void whipped_cream()
{
turntable(3);
sleep(2.0);
printf("\nWhipped cream? (1, 2, or 3)"); /* (188) */
sleep(5.0);
printf("\nPress stop for next option");

if(digital(15) == 1)
solo_wc(1, 3);
if(digital(14) == 1)
solo_wc(2, 3);
if(digital(13) == 1)
solo_wc(3, 3);

stop_press();
}
/* (201) */
void main()
{
while(!stop_button()){
turntable(0);
sleep(2.0);
instructions();
sleep(2.0);
drymix();
sleep(2.0);
chocolate();
sleep(2.0); /* (212) */
whipped_cream();
sleep(2.0);
turntable(0);
printf("\nThank you and ENJOY!!!");
sleep(10.0);
}
}