James McKenzie 5 лет назад
Родитель
Сommit
a7d02d9a9b
1 измененных файлов: 55 добавлений и 9 удалений
  1. +55
    -9
      Theremin/Theremin.ino

+ 55
- 9
Theremin/Theremin.ino Просмотреть файл

@@ -15,19 +15,28 @@ void setup() {

pinMode(11, OUTPUT); //the trigger pin
pinMode(12, INPUT); //echo pin
if (digitalRead(6) ==HIGH){
mode = 0;
mode = 1;
}

}

void loop() {

if (digitalRead(6) ==HIGH){
mode = 0;
}else{
mode = 1;
}
float note = 0;
if (digitalRead(7) == LOW){
if (mode == 0){
digitalWrite(13, HIGH);
tone(8, getNote());
note = tune(getNote());
}
else{
note = getNote();
}
digitalWrite(13, HIGH);
Serial.print(note); //print units after the distance
Serial.println(" hz"); //print units after the distance
tone(8, note);
}
else{
noTone(8);
@@ -50,7 +59,44 @@ float getNote()

calculatedDistance = 1760;
}
Serial.print(calculatedDistance); //print units after the distance
Serial.println(" hz"); //print units after the distance

return calculatedDistance;
}
float tune(float toTune){
if (toTune> 523.75){ //C5
return 523.75;
}
if (toTune> 493.88){ //B4
return 493.88;
}
if (toTune> 440){ //A4
return 440;
}
if (toTune> 392){ //G4
return 392;
}
if (toTune> 349.23){ //F4
return 349.23;
}
if (toTune> 329.63){ //E5
return 329.63;
}
if (toTune> 293.66){ //D4
return 293.66;
}
if (toTune> 261.63){ //C4
return 261.63;
}
if (toTune> 246.94){ //B3
return 246.94;
}
if (toTune> 220){ //A3
return 220;
}
if (toTune> 196){ //G3
return 196;
}
if (toTune> 174.61){ //F3
return 174.61;
}
}

Загрузка…
Отмена
Сохранить