Jump to content

Controlling an RC car with a TI-99

Recommended Posts

So I made a post about this a while ago and thought I'd give a bit of an update. I actually got it working, as you can see in this quick video I made. I basically combined these two articles about arduino programs, one for frequency detection and another for controlling the car. I'll provide the complete code below, but it takes in the frequency from the Ti-99 audio and triggers the command to run the car forward. The audio from the Ti-99 is filtered through a circuit described in this article. Currently the code's only set up to make the car go forward, but the other directions can be added.

You'll also need this library for this code to work

#include <DigitalPin.h>
//sine wave freq detection with 38.5kHz sampling rate and interrupts
//by Amanda Ghassaei
//July 2012
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
//create the forward object to make the car move
DigitalPin forward(8);
DigitalPin backward(9);
//clipping indicator variables
boolean clipping = 0;
//data storage variables
byte newData = 0;
byte prevData = 0;
//freq variables
unsigned int timer = 0;//counts period of wave
unsigned int period;
int frequency;
void setup(){
pinMode(13,OUTPUT);//led indicator pin
cli();//diable interrupts
//set up continuous sampling of analog pin 0
//clear ADCSRA and ADCSRB registers
ADMUX |= (1 << REFS0); //set reference voltage
ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
ADCSRA |= (1 << ADATE); //enabble auto trigger
ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
ADCSRA |= (1 << ADEN); //enable ADC
ADCSRA |= (1 << ADSC); //start ADC measurements
sei();//enable interrupts
ISR(ADC_vect) {//when new ADC value ready
prevData = newData;//store previous value
newData = ADCH;//get value from A0
if (prevData < 127 && newData >=127){//if increasing and crossing midpoint
period = timer;//get period
timer = 0;//reset timer
if (newData == 0 || newData == 1023){//if clipping
PORTB |= B00100000;//set pin 13 high- turn on clipping indicator led
clipping = 1;//currently clipping
timer++;//increment timer at rate of 38.5kHz
void loop(){
if (clipping){//if currently clipping
PORTB &= B11011111;//turn off clippng indicator led
clipping = 0;
frequency = 38462/period;//timer rate/period
//print results
Serial.println(" hz");
if (frequency >= 105&& frequency <= 115) {
  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...