/* will listen for the w,a,s,d keys*/ /*NOTE: key mappings may be different for different computers*/ /*especially laptops. Try sending different keys and seeing*/ /*they're output values to get the program to work*/ #define LEFT_MOTOR 0 #define RIGHT_MOTOR 3 void main() { int a; printf("\nwaiting for start"); start_press(); /*no longer listen for IC*/ disable_pcode_serial(); printf("started\n"); /*loop until the stop button is held down AND a key is pressed*/ while(!stop_button()) { /*block until a character arrives*/ a=serial_getchar(); printf("\n%d",a); /*switch on that character and decide what to do*/ if (a == 119) { motor(LEFT_MOTOR,100); motor(RIGHT_MOTOR,100); } if (a == 115) { motor(LEFT_MOTOR,-100); motor(RIGHT_MOTOR,-100); } if (a == 97) { motor(LEFT_MOTOR,-100); motor(RIGHT_MOTOR,100); } if (a == 100) { motor(LEFT_MOTOR,100); motor(RIGHT_MOTOR,-100); } sleep(0.05); motor(LEFT_MOTOR,0); motor(RIGHT_MOTOR,0); } /*]listen to IC again.*/ enable_pcode_serial(); printf("\nback in pcode mode"); }