I have this frequencys (NOTE) AND i would like to relate with the distance if my ultrasonic sensor
Thanks in advance
#include <NewPing.h> // https://bitbucket.org/teckel12/arduino-new-ping/downloads/
const byte UltrasonicPin = 5;
const unsigned int MaxDistance = 200;
NewPing sonar(UltrasonicPin, UltrasonicPin, MaxDistance);
#include <SoftwareSerial.h>
SoftwareSerial DFPlayerSerial(10, 11); // RX, TX
#include <NewPing.h>
float distance() //distance-reprdouce one frequency
void setup() {
{
Serial.begin(9600);
DFPlayerSerial.begin(9600);
}
void loop()
{
Serial.begin(9600);
//delay(noteDuration);
delay (0);
if (distance < 10) {
// distance less than 10cm
tone(4, melody[thisNote],noteDuration*1);
REPRODUCE NOTE1
} else if (distance < 20) {
// distance between 10cm and 20cm
reproduce NOTE2
} else if (distance < 50) {
// distance between 20cm and 50cm
reproduce NOTE3
} else {
// distance more than 50cm
reproduce NOTE4
}
}
#define NOTE_1 300
#define NOTE_2 280
#define NOTE_3 260
//#define NOTE_4 240
//#define NOTE_5 220
//#define NOTE_6 200
//#define NOTE_7 180
//#define NOTE_8 160
//#define NOTE_9 140
//#define NOTE_10 120