this was a short experiment where i wanted to see how analog AC signals from a guitar were received and converted to digital signals by the ATMEGA328. to “hear” the results along with seeing the numbers as i plucked the strings, i combined digitalWrite() and the tone() functions to output on the same pin giving it a broken-video-game effect just for fun. overall, pretty useless, but the idea of extrapolating the tonal frequency from the input voltage (or at least getting close by using an array of predefined tonal constants) seems feasible enough.
here’s a bit of the code i was using.
const int inputPin = 2; const int outputPin = 10; void setup() { Serial.begin(9600); pinMode(outputPin, OUTPUT); pinMode(inputPin, INPUT); } void loop() { Serial.println(analogRead(inputPin)); int frequency = map(analogRead(inputPin), 0, 1023, 82.4, 5000); int duration = map(analogRead(inputPin), 0, 1023, 0, 1000); if(duration != 0) { digitalWrite(outputPin, analogRead(inputPin)); tone(outputPin, frequency, duration); } delay(duration); }
Leave a Reply
You must be logged in to post a comment.