Software

      The program that runs the blender makes use of two functions in addition to the main, one makes a small drink and the other makes a large drink. In the main program it continually checks to see if one of the start buttons has been pushed and if the error light is out. Once these conditions have been met it calls the appropriate function to make a drink. After the drink is made the condition variables are reset and the program returns to polling the error switches and start buttons. A flow chart and the complete program are shown below.

Complete Program

int in_progress_weak = 0;
int in_progress_strong = 0;
int count = 0;
int j = 0;

/* digital(15) is the error switches
digital(10) is the weak drink start
digital(11) is the strong drink start button

motor(0) stepper coil 0
motor(1) stepper coil 1
motor(2) is the valve
motor(3) is the mixer
*/
/*********************************************/
void make_weak(){
/* while (digital(15)){*/
printf("making weak\n");
for(j=1;j<=2;j++){ /* how many slides */
while (count < 22){ /* # of stepper cycles */
fd(0); fd(1); sleep(0.0);
bk(0); fd(1); sleep(0.0);
bk(0); bk(1); sleep(0.0);
fd(0); bk(1); sleep(0.0);
count++;
}
reset_system_time();
while(seconds()<=1.0){}
while (count > 0){ /* returning to start */
fd(0); bk(1); sleep(0.0);
bk(0); bk(1); sleep(0.0);
bk(0); fd(1); sleep(0.0);
fd(0); fd(1); sleep(0.0);
count--;
}
reset_system_time();
while(seconds()<=1.0){}
} /* end of for loop */

reset_system_time();
motor(2,100);
motor(2,100);
motor(2,100);
motor(2,100);
motor(3,0);
motor(3,0);
motor(3,0);
motor(3,0);
while (seconds() <= 40.0){ /* time to fill glass */
printf("time left fill: %f\n",40.0-seconds());
}
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);

reset_system_time();
motor(3,100);
while (seconds() <= 8.0){ /* time to mix drink */
printf("time left mix: %f\n",8.0-seconds());
}
motor(3,0);


printf("light ready diode now\n");
bit_set(0x1000, 0x80);
in_progress_weak = 0;

reset_system_time();
while(seconds() <= 10.0){}
bit_clear(0x1000, 0x80);
/* printf("Enter drink preference\n"); */
}
/*********************************************/
void make_strong(){
/* while (digital(15)){*/
printf("making strong\n");
for(j=1;j<=4;j++){ /* how many slides */
while (count < 22){ /* # of stepper cycles */
fd(0); fd(1); sleep(0.0);
bk(0); fd(1); sleep(0.0);
bk(0); bk(1); sleep(0.0);
fd(0); bk(1); sleep(0.0);
count++;
}
reset_system_time();
while(seconds()<=1.0){}
while (count > 0){ /* returning to start */
fd(0); bk(1); sleep(0.0);
bk(0); bk(1); sleep(0.0);
bk(0); fd(1); sleep(0.0);
fd(0); fd(1); sleep(0.0);
count--;
}
reset_system_time();
while(seconds()<=1.0){}
} /* end of for loop */

reset_system_time();
motor(2,100);
motor(2,100);
motor(2,100);
motor(2,100);
motor(2,100);
motor(3,0);
motor(3,0);
motor(3,0);
motor(3,0);
motor(3,0);
while (seconds() <= 60.0){ /* time to fill glass */
printf("time left fill: %f\n",60.0-seconds());
}
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);
motor(2,0);

reset_system_time();
motor(3,100);
while (seconds() <= 8.0){ /* time to mix drink */
printf("time left mix: %f\n",8.0-seconds());
}
motor(3,0);


printf("light ready diode now\n");
bit_set(0x1000,0x80);
in_progress_strong = 0;
reset_system_time();
while(seconds() <= 10.0){}
bit_clear(0x1000, 0x80);
/* printf("Enter drink size\n"); */

}
/*********************************************/

void main(){
bit_set(0x1026,0x80);
bit_clear(0x1000, 0x80);
while(1){
while(1){
printf("Enter drink size\n");
if (((digital(15)))&&(digital(10))){
in_progress_weak = 1;
printf("calling weak drink\n");
break;
}
if (((digital(15)))&&(digital(11))){
in_progress_strong = 1;
printf("calling strong drink\n");
break;
}
}
if(in_progress_strong) make_strong();
if(in_progress_weak) make_weak();
}
}