Arduino – the beginnings of a journey

, dating services in atlanta , Leave a comment

Warning: geek post to follow.

Anyone who has been unlucky enough to know me over the last 3 weeks will realise my obsession with all things Arduino has got out of hand. From the initial buzz of realising “I can do ANYTHING with one of these things” to the late-night shopping sprees with Amazon sellers who distribute from warehouses in Hong Kong (I placed my 18th Ardunio order in 3 weeks yesterday night at 4am … gladly most of these purchases come in around a quid per unit so it’s not even that expensive a hobby so far), it has been a fun journey so far.

My first stop was to give myself a brief refresher in electronics and coding in C, so I followed some excellent examples from the Arduino “getting started” book. Right, after 13 minutes of making a little circuit that pulses an LED at the speed set by a knob and a few other beginner projects, I thought I should dive right in and do something serious.

I mean *REALLY* serious. A piezo tune generator. #sarcasm

The key array basically sets out the diatonic notes of a scale for 8 notes. The ones following those 8 notes are a random selection of semitones that I snuck in just so that I could program “You are my sunshine”. Musos will understand why.

Next instalment: how to control your hi-fi volume using an Arduino, RF signals, and a rotary encoder!

Here’s the sketch:

// Whack a piezo between 8 and GND
// Comment or uncomment the tune array definitions

int key[] = {261,294,330,349,392,440,494,523,587,622,659,698,784,880,987,1046};

// "You're Just Too Good To Be True"
// int tune[] = {5,5,5,6,5,3,5,0,5,5,5,6,5,3,5,0,5,5,5,6,5,3,5,0,5,5,4,5,4,5,4,0,4,4,3,5,4,3,4,0,4,4,4,4,3,2,3,0,3,3,3,3,2,1,2,0,2,2,2,2,1,1,1,0};

// "You are my sunshine"
int tune[] = {5,8,9,11,0,11,0,0,11,10,11,8,0,8,0,0,8,9,11,12,0,14,0,0,14,13,12,11,0,0,0,0,8,9,11,12,0,14,0,0,14,13,12,11,0,8,0,0,5,8,9,11,0,0,12,9,9,0,11,8,0,0,0,0};

int tunelength = sizeof(tune) / sizeof(int);
void setup() {

void loop() {
int currentnoteindex = 0;
while (currentnoteindex < (tunelength)) { if (tune[currentnoteindex] == 0) { delay(180); currentnoteindex++; } else { tone(8,key[tune[currentnoteindex++]-1],90); delay(180); } } currentnoteindex = 0; }


Leave a Reply