Accelerometer music

Using the Arcbotics Sparki lesson to learn about the accelerometer, and I made my own version:


#include // include the sparki library
void setup()
{
}
void loop() {
sparki.clearLCD();
float x = sparki.accelX();
float y = sparki.accelY();
float z = sparki.accelZ();
sparki.print("Accel X: ");
sparki.println(x);
sparki.print("Accel Y: ");
sparki.println(y);
sparki.print("Accel Z: ");
sparki.println(z);
sparki.updateLCD();
if (y>=5)
{
sparki.beep(540,100);
delay(500);
}
if ((y<5)&&(y>=0))
{
sparki.beep(440,100);
delay(500);
}
if((y<0)&&(y>=-3))
{
sparki.beep(340,100);
delay(500);
}
if (y<-3)
{
sparki.beep(240,100);
delay(500);
}
}

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s