Explorar el Código

Changed Mode Port, and added a velocity button

master
James McKenzie hace 5 años
padre
commit
29e79f00f6
Se han modificado 1 ficheros con 14 adiciones y 3 borrados
  1. +14
    -3
      Theremin/Theremin.ino

+ 14
- 3
Theremin/Theremin.ino Ver fichero

@@ -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;
} }


Cargando…
Cancelar
Guardar