Skip to content

Tone Lab Fun

October 20, 2011

I was eager to get to the fun part of the tone lab. I have this ADXL335 breakout sitting in my bins that I wanted to play around with anyway. I found someone online who suggested just putting the breakout board into the analog pins and setting the A4 and A5 as ground and Vcc, respectively. You do this by using them as digital pins and setting them high or low. I summed up the analog readings from the three axes and mapped that to a range of frequencies to be played by Tone. Here’s the code:

const int groundpin = 18;
const int powerpin = 19; 
const int xpin = A3; 
const int ypin = A2;
const int zpin = A1; 

int sum = 0;

void setup()
{

  Serial.begin(9600);

  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW);
  digitalWrite(powerpin, HIGH);
}

void loop()
{
  sum = analogRead(xpin) + analogRead(ypin) + analogRead(zpin);
  Serial.println(sum);
  float frequency = map(sum, 1500, 2000 , 100, 2000);
  tone(8, frequency, 10);
}

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: