Videogamecollector123 Posted April 13, 2014 Share Posted April 13, 2014 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 //http://www.instructables.com/id/Arduino-Frequency-Detection/ //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(; 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(){ Serial.begin(9600); pinMode(13,OUTPUT);//led indicator pin cli();//diable interrupts //set up continuous sampling of analog pin 0 //clear ADCSRA and ADCSRB registers ADCSRA = 0; ADCSRB = 0; 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.print(frequency); Serial.println(" hz"); if (frequency >= 105&& frequency <= 115) { forward.on(); backward.off(); } else { forward.off(); backward.off(); } } 3 Quote Link to comment Share on other sites More sharing options...
RobertLM78 Posted April 13, 2014 Share Posted April 13, 2014 I'd sure like to be able to watch the video - it's currently set to private. Quote Link to comment Share on other sites More sharing options...
Videogamecollector123 Posted April 13, 2014 Author Share Posted April 13, 2014 (edited) Sorry about that, should be fixed now. Guess the youtube app on my phone just uploads video's private as default. Edited April 13, 2014 by Videogamecollector123 Quote Link to comment Share on other sites More sharing options...
RobertLM78 Posted April 13, 2014 Share Posted April 13, 2014 Awesome! Reminds me of Vorticon's robot project . Quote Link to comment Share on other sites More sharing options...
+Vorticon Posted April 14, 2014 Share Posted April 14, 2014 Very cool! Never thought of controlling an object with TI sounds This would make a great demo at the upcoming Chicago Faire in November. Nice work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.