Teensy - RC, RC PAD, Play games with the RC Controller as Game Controller, RC servo, Radio Controlled, play games handicappedThis page is under construction! I like RC (radio controlled) vehicles and thought it would be great to play racing games with the RC controller. I checked the internet and as always, someone else had already that idea. One solution is using the Andurino and another is using Flightsim. I decided to use my own solution. I am using a Teensy, some wires and a 6 channel RC sender/receiver. It is also a great soluton for handicapped people to play racing games. Hardware
Source codeThis Software is
Download: teensy3-rc-20220728.zip Download: teensy3-rcpad-20220728.zip Videos
How it worksThe RC receiver gives continuous pulses as output. The pulse length is between a minimum and a maximum length. The length of the pulse is corresponding with the angle of the servo or the speed of the motor. Every channel has its own pulse output. I read the output of the RC receiver with the Teensy using the digital input pins and interrupts on state change. The RC receiver can work with 4,8V-12V and is powered by the 5V of the Teensy USB connection.
Output from the Teensy as Serial USB device (program teensy3-rc) and minicomChannel exampleChannel 1, controlled by the steering wheel of the RC sender.
Pulse diagramThese values are from my receiver. Use the output option to get the values from your hardware. RC PAD - Game Controller
TODO: Desciptions for RC sender buttons - emulate buttonsThe RC sender buttons are acting as switches. For example, when you press the button for channel 6, the button changes the state (pulse duration > 1000µs) and keeps it. When you press again, it changes the state (pulse duration < 1000µs) and keeps it. This behaviour is useful for RC vehicles, but for gaming you need buttons that are acting as buttons. The Two-State Button function emulates a 200ms button press when the sender button state switches. Code snippets: Two-State Button /* * channel : Receiver channel. * toggle_time: Pulse time tipping point. * press_ms : Keep pressed state for num milli seconds. * * Return: Emulated button is/isn't pressed. */ unsigned char RC_HandleButton (int channel, int toggle_time, int press_ms) { unsigned int idx = channel - 1; unsigned long ms = millis(); unsigned char is_pressed = 0; if ((rc_bt_state[idx] == 0) && (rc_time_up[idx] > toggle_time)) { rc_bt_state[idx] = 1; rc_bt_pressed_time[idx] = ms + press_ms; } else if ((rc_bt_state[idx] == 1) && (rc_time_up[idx] < toggle_time)) { rc_bt_state[idx] = 0; rc_bt_pressed_time[idx] = ms + press_ms; } // Is pressed time over? If not then set is_pressed. if (rc_bt_pressed_time[idx] > ms) { is_pressed = 1; } return is_pressed; } /*******************************/ #define PRESS_MS 200 /*******************************/ report[3] = 0; report[3] |= RC_HandleButton (6, 1000, PRESS_MS) << 4; report[3] |= RC_HandleButton (5, 1800, PRESS_MS) << 5; report[3] |= RC_HandleButton (3, 1200, PRESS_MS) << 6; Code snippets: Tri-State Switch unsigned char RC_GetTriStateSwitch (int channel, int time1, int time2) { unsigned int idx = channel - 1; if (rc_time_up[idx] < time1) return 0; else if (rc_time_up[idx] < time2) return 1; return 2; } /*******************************/ #define RC_MODE1 1000 #define RC_MODE2 2000 /*******************************/ unsigned char mode = RC_GetTriStateSwitch (4, RC_MODE1, RC_MODE2); switch (mode) { case 0: Debug outputFor debugging, you can connect the Teensy with an USB Serial Cable an view the output for example with the program minicom. Wire details are shown at the "Teensy - RC/RC PAD" schematic and in the "Teensy - USB/UART" area. Mode informationVarious blink modes when sender is not powered on startup and for "gaming mode", "menu mode", "alternate buttons mode". Controller mappingUsing handicappedTodo Photos© 2022 by
Elmar Hanlhofer |