// Control robot movements by serial communication // Notice the arrangement of keys on the PC numeric pad #include "motor.h" main() { int x; writes("comm", 500); setcomm(9600); loop { do x = readm(232, 0); while(x == -1); // wait to receive a character writec(0, x, 10); writec(232, x, 0); switch(x) { case '8': drive( 1, 1, 0); break; // forward case '7': drive(-1, 1, 0); break; // spin left case '9': drive( 1, -1, 0); break; // spin right case '2': drive(-1, -1, 0); break; // backward case '4': turn_left(); break; case '6': turn_right(); break; case '5': stop_all(); break; case '0': stop_all(); writes("end", 2000); exit(); break; // stop and exit } } } turn_left() { drive(-1, -1, 500); // backward drive(-1, 1, 500); // turn left } turn_right() { drive(-1, -1, 500); // backward drive( 1, -1, 500); // turn right }