/* place your #defines and global variable declarations here */ void program() { int lastval = 0, currval; while (!stop_button()) { motor(3, currval = (knob() - 128)); if (currval != lastval) { printf("Powering motor 3 at %d\n", currval); lastval = currval; } } } /* put your functions and subroutines here */ /*********************************************************************/ /********* FROM HERE ON ARE MENU ROUTINES: LEAVE AS IS ***************/ /*********************************************************************/ void main() { while (1==1) { ao(); menu(); ao(); program(); } } char menu_choices[7][32] = {"Any button = run user program","MOTOR: Start=FWD 0 : Stop=RVS","MOTOR: Start=FWD 1 : Stop=RVS","MOTOR: Start=FWD 2 : Stop=RVS","MOTOR: Start=FWD 3 : Stop=RVS","Any button = Show Analogs","Any button = Show Digitals"}; int menu_motorstate = 0; int menu_choice = 9; int menu_motorpower = 80; void menu() { while (1) { while (stop_button() || start_button()) {} sleep(0.05); while (stop_button() || start_button()) {} sleep(0.05); while (stop_button() || start_button()) {} sleep(0.05); while (stop_button() || start_button()) {} menu_choice = select_string(menu_choices, 7); if ((menu_choice == -1) || (menu_choice == 0)) { printf("\n\n"); return; } else { if (menu_choice == 1) { motor(0, menu_motorpower); } if (menu_choice == 2) { motor(0, -menu_motorpower); } if (menu_choice == 3) { motor(1, menu_motorpower); } if (menu_choice == 4) { motor(1, -menu_motorpower); } if (menu_choice == 5) { motor(2, menu_motorpower); } if (menu_choice == 6) { motor(2, -menu_motorpower); } if (menu_choice == 7) { motor(3, menu_motorpower); } if (menu_choice == 8) { motor(3, -menu_motorpower); } if (menu_choice == 9) { while (start_button() || stop_button()) {} display_analogs(); } if (menu_choice == 10) { while (start_button() || stop_button()) {} display_analogs(); } if (menu_choice == 11) { while (start_button() || stop_button()) {} display_digitals(); } if (menu_choice == 12) { while (start_button() || stop_button()) {} display_digitals(); } while (stop_button() || start_button()) {} ao(); } } } void display_digitals() { int i, a; while (!start_button() && !stop_button()) { printf("digitals 7->15: "); for(i=7; i<=15; i++) { a = digital(i); printf("%d",a); } printf("\n"); sleep(0.1); } } void display_analogs() { int i, a; while (!start_button() && !stop_button()) { for(i=0; i<=6; i++) { a = analog(i); if (a < 10) { printf(" "); } if (a < 100) { printf(" "); } printf("%d ",a); } printf("\n"); sleep(0.1); } } int select_string(char choices[][],int n) { int selection,last_selection=-1,coarseness; if(n>_array_size(choices)) n=_array_size(choices); coarseness=255/(n-1); while(!(stop_button() || start_button())) { selection=(knob())/coarseness; if(selection!=last_selection) { printf("%s\n",choices[selection]); sleep(0.1); last_selection=selection; } } if (start_button()) { return selection * 2 - 1; } else { return selection * 2; } }