/* Remote controller for a car. When a touch button is pressed/released the infrared transmitter is used to send a message to the car signaling the state change. 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 "InputPorts.h" /* State of the two touch buttons on the remote controller */ #define LeftPressed 1 #define LeftReleased 2 #define RightPressed 3 #define RightReleased 4 #define TouchThreshold 950 byte Touch1State( void ) { return ( ( Port1Raw() > TouchThreshold ) ? FALSE : TRUE ); } byte Touch3State( void ) { return ( ( Port3Raw() > TouchThreshold ) ? FALSE : TRUE ); } /* Actuators */ #include "IR.h" void Transmit( word m ) { IRTransmit(0,m); } void _start( void ) { byte Touch1, PreviousTouch1, Touch3, PreviousTouch3; ButtonsInit(); while ( ! Running ){ lcd_show_int16(BatteryLevel()); BusyPauseMS(300); } IRInit(); IREnableInterrupts(); PreviousTouch1 = Touch1State(); PreviousTouch3 = Touch3State(); while ( Running ) { lcd_show_int16(Touch1State()); lcd_show_digit(Touch3State()); Touch1 = Touch1State(); if ( Touch1 && ( ! PreviousTouch1 ) ) { PreviousTouch1 = TRUE; Transmit(LeftPressed); } else if ( ( ! Touch1 ) && PreviousTouch1 ) { PreviousTouch1 = FALSE; Transmit(LeftReleased); } Touch3 = Touch3State(); if ( Touch3 && ( ! PreviousTouch3 ) ) { PreviousTouch3 = TRUE; Transmit(RightPressed); } else if ( ( ! Touch3 ) && PreviousTouch3 ) { PreviousTouch3 = FALSE; Transmit(RightReleased); } } IRDisableInterrupts(); IRClose(); RCX_Reset(); }