// Control robot movements by an IR remote controller // Notice the arrangement of keys on the numeric pad // Speed control by PWM method #include "motor.h" #define SPD 1 // 1..10, 1=slowest int cmd=100; // command, initialized to a dummy value main() { int ch; writes("rc2", 500); loop { ch = ircode(); if(1 <= ch && ch <= 9) cmd = ch; } } speed() timer ITV { switch(cmd) { case 2: drive( 1, 1, SPD); break; // forward case 8: drive(-1, -1, SPD); break; // backward case 1: drive(-1, 1, SPD); break; // spin left case 3: drive( 1, -1, SPD); break; // spin right case 4: drive( 0, 1, SPD); drive(1, 1, SPD); break; // turn left; case 6: drive( 1, 0, SPD); drive(1, 1, SPD); break; // turn right case 5: stop_all(); break; // standstill } }