/* A program for a remote controlled car. Infrared communication is used to send the state of the touch buttons on the remote controller to the car. The state determinds the state of car motors. Last updated 4.3.01. */ #include "RCX_String.h" #include "RCX_Control.h" #include "H8.h" #include "Time.h" #include "LCD.h" #include "Battery.h" #include "Buttons.h" /* Sensors */ #include "IR.h" /* Actuators */ #include "OutputPorts.h" /* State of the two touch buttons on the remote controller */ #define LeftPressed 1 #define LeftReleased 2 #define RightPressed 3 #define RightReleased 4 word RemoteState( void ) { word m1, m0, t; while ( Running && ( ! IRReceive( & m1, & m0, & t) ) ) /* Busy waiting loop */ ; return m0; } void _start( void ) { word state; ButtonsInit(); while ( ! Running ){ lcd_show_int16(BatteryLevel()); BusyPauseMS(300); } IRInit(); IREnableInterrupts(); while ( Running ) { state = RemoteState(); lcd_show_int16(state); switch ( state ) { case LeftPressed: PortA(OnPos); break; case LeftReleased: PortA(Float); break; case RightPressed: PortC(OnPos); break; case RightReleased: PortC(Float); break; } } IRDisableInterrupts(); IRClose(); RCX_Reset(); }