Note that this blog is discontinued. You can find my new blog here: Daniel Nouri's Blog.
After going through part two of this Arduino sound tutorial, I made this little synthesizer.
Click here if you can't see the video.
You can see that it starts out with a constant frequency that can be varied with the potentiometer.
An LFO is added to the frequency once I push the button. Successive button pushes will change the amplitude of the LFO.
While the aforementioned tutorial explains how to connect Arduino with your PC sound card to get sound, I simply plugged in a Piezo buzzer. The advantage being that this synth is totally self-contained and portable, so I could use it in the train (I won't!). The downside is that the audio quality is bad, and it's even worse in the video.
Everything I needed to build this came with the Arduino workshop kit (50 EUR). This includes the Arduino Diecimila itself, potentiometer, buzzer, breadboard, and button.
The button press detection in the Wiring code doesn't work properly. A good implementation would probably need to use interrupt handlers. I ignored this issue for now:
int buttonPin = 7;
int buzzerPin = 8;
int potPin = 2;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void inner_loop(int j) {
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(j*16 + analogRead(potPin));
digitalWrite(buzzerPin, LOW);
delayMicroseconds(j*16 + analogRead(potPin));
}
void loop() {
int val = digitalRead(buttonPin);
int factor = 0;
for (int i = 100; i > 0; i--) {
inner_loop(i * factor);
}
// XXX: This doesn't work very well
if (digitalRead(buttonPin) != val && val == HIGH) {
factor++;
if (factor > 3)
factor = 0;
}
for (int i = 0; i < 100; i++) {
inner_loop(i * factor);
}
}
posted at: 17:58 |
0 comments |
category: /devel/hardware
|
permanent link |
add to del.icio.us or digg it
| < | May 2008 | > | ||||
| Su | Mo | Tu | We | Th | Fr | Sa |
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Feed of all categories:
rss |
atom