Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define trigPin 3
- #define echoPin 2
- void setup(){
- Serial.begin(9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- }
- void loop(){
- int duration, distance;
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (duration / 2) / 29.1;
- Serial.print(distance);
- Serial.println(" cm");
- //
- int thisPitch = map(distance, 0, 200, 2093, 22);
- int standardPitch = 1500;
- // noteList
- int noteC0 = 262;
- int noteC0sharp = 278;
- int noteD0 = 294;
- int noteD0sharp = 312;
- int noteE0 = 330;
- int noteF0 = 349;
- int noteF0sharp = 370.5;
- int noteG0 = 392;
- int noteG0sharp = 416;
- int noteA1 = 440;
- int noteA1sharp = 467;
- int noteB1 = 494;
- int noteC1 = 523;
- int noteC1sharp = 555;
- int noteD1 = 587;
- int noteD1sharp = 623;
- int noteE1 = 659;
- int noteF1 = 698;
- int noteF1sharp = 741;
- int noteG1 = 784;
- int noteG1sharp = 832;
- int noteA2 = 880;
- int noteA2sharp = 934;
- int noteB2 = 988;
- int noteC2 = 1047;
- //----------------
- //settings here
- int firstPitch = 1500;
- int secondPitch = 1000;
- int resetPitch = 500;
- int beepCount = 0;
- if (distance > 8 && beepCount <= 3)
- {
- //tune here:-
- tone(4, noteE0); //1
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //2
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //3
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //4
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //5
- delay(300);
- noTone(4);
- delay(100);
- tone(4, noteF0); //6
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //7
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //8
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //9
- delay(150);
- noTone(4);
- delay(50);
- tone(4, noteF0); //10 half note #1
- delay(50);
- noTone(4);
- delay(50);
- tone(4, noteF0); //11 half note #2
- delay(50);
- noTone(4);
- delay(50);
- tone(4, noteF0); //12
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //13
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteD0sharp); //14
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteE0); //15
- delay(100);
- noTone(4);
- delay(100);
- tone(4, noteF0); //16
- delay(100);
- noTone(4);
- delay(300);
- //beepCount = beepCount + 1;
- }
- /* if (distance < 2 && beepCount <= 3)
- {
- tone(4, resetPitch);
- beepCount = 0;
- }
- */
- noTone(4);
- delay(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement