Changed Mode Port, and added a velocity button

This commit is contained in:
James McKenzie 2019-04-29 20:26:20 +12:00
parent dbb758c7ff
commit 29e79f00f6

View File

@ -5,25 +5,36 @@
*/ */
int mode; int mode;
void setup() { void setup() {
pinMode(0, INPUT_PULLUP); pinMode(6, INPUT_PULLUP);
pinMode (13, OUTPUT); pinMode (13, OUTPUT);
pinMode(8, OUTPUT); pinMode(8, OUTPUT);
pinMode (7, INPUT_PULLUP);
Serial.begin (9600); //set up a serial connection with the computer Serial.begin (9600); //set up a serial connection with the computer
pinMode(11, OUTPUT); //the trigger pin pinMode(11, OUTPUT); //the trigger pin
pinMode(12, INPUT); //echo pin pinMode(12, INPUT); //echo pin
if (digitalRead(0) ==HIGH){ if (digitalRead(6) ==HIGH){
mode = 0; mode = 0;
mode = 1; mode = 1;
} }
} }
void loop() { void loop() {
if (digitalRead(7) == LOW){
if (mode == 0){ if (mode == 0){
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
tone(8, getNote()); tone(8, getNote());
} }
}
else{
noTone(8);
}
} }
float getNote() float getNote()
{ {
float echoTime; float echoTime;
@ -35,7 +46,7 @@ float getNote()
echoTime = pulseIn(12, HIGH); echoTime = pulseIn(12, HIGH);
calculatedDistance = echoTime / 8; calculatedDistance = echoTime / 8;
calculatedDistance += 110; calculatedDistance += 110;
if (calculatedDistance > 1760){ // if (calculatedDistance > 1760){ //git
calculatedDistance = 1760; calculatedDistance = 1760;
} }