Using Infrared Distance Sensor with GR-SAKURA

Author: FUJIKEN

Original Location: http://japan.renesasrulz.com/gr_user_forum_japanese/f/4/t/645.aspx

------------------------------------------------------

I made a Thereminvox-like sound instrument with GR-SAKURA and GP2Y0A31 (Sharp's  Infrared distance sensor).  GR-SAKURA generates a musical scale based on distance.  You need to use your  hand to reflect IR-light from 5cm to 30cm.

Demo Video:http://www.youtube.com/watch?v=MNwCbkaP7dc&feature=youtu.be

/*GR-SAKURA Sketch Template Version: V1.00*/

#include <rxduino.h>

#define A0 14

#define speaker 8

int a;

void setup()

{

  //Serial.begin(38400);

 pinMode(A0, INPUT);

}

void loop()

{

a = analogRead(A0) ;

Serial.println(a);

if ((a>550) && (a<700)) {

Serial.println("5cm ド");  // 5cm Do

Serial.println(a);

tone(speaker,262);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>450) && (a<540)) {

Serial.println("7cm レ");  // 7cm Re

Serial.println(a);

tone(speaker,294);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>400)&&(a<440)) {

Serial.println("10cm ミ");  // 10cm Mi

Serial.println(a);

tone(speaker,330);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>330)&&(a<390)) {

Serial.println("12cm ファ");   // 12cm Fa

Serial.println(a);

tone(speaker,349);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>250)&&(a<320)) {

Serial.println("15cm ソ");   // 15cm Sol

Serial.println(a);

tone(speaker,392);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>210)&&(a<240)) {

Serial.println("20cm ラ");  // 20cm La

Serial.println(a);

tone(speaker,440);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>150) && (a<200)) {

Serial.println("30cm シ");  // 30cm Ti

Serial.println(a);

tone(speaker,494);

delay(2000);

noTone(speaker);

delay(2000);

}

else if ((a>100) && (a<140)) {

Serial.println("40cm 高いド");  // 40cm High-Do

Serial.println(a);

tone(speaker,523);

delay(2000);

noTone(speaker);

delay(2000);

}

}

Parents Reply Children
No Data