Linear Signal Generator Working
This commit is contained in:
parent
81fc75702e
commit
5bd9d3b6c8
@ -8,6 +8,10 @@ void setup() {
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
pinMode (13, OUTPUT);
|
||||
pinMode(8, OUTPUT);
|
||||
Serial.begin (9600); //set up a serial connection with the computer
|
||||
|
||||
pinMode(11, OUTPUT); //the trigger pin
|
||||
pinMode(12, INPUT); //echo pin
|
||||
if (digitalRead(0) ==HIGH){
|
||||
mode = 0;
|
||||
}
|
||||
@ -19,6 +23,25 @@ void setup() {
|
||||
void loop() {
|
||||
if (mode == 0){
|
||||
digitalWrite(13, HIGH);
|
||||
tone(8, 440);cd
|
||||
tone(8, getNote());
|
||||
}
|
||||
}
|
||||
float getNote()
|
||||
{
|
||||
float echoTime;
|
||||
float calculatedDistance;
|
||||
digitalWrite(11, HIGH);
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(11, LOW);
|
||||
|
||||
echoTime = pulseIn(12, HIGH);
|
||||
calculatedDistance = echoTime / 8;
|
||||
calculatedDistance += 110;
|
||||
if (calculatedDistance > 1720){
|
||||
|
||||
calculatedDistance = 880;
|
||||
}
|
||||
Serial.print(calculatedDistance); //print units after the distance
|
||||
Serial.println(" hz"); //print units after the distance
|
||||
return calculatedDistance;
|
||||
}
|
||||
|
45
Theremin/Theremin/Theremin.ino
Normal file
45
Theremin/Theremin/Theremin.ino
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
*@author James McKenzie
|
||||
*@lang C89 Based
|
||||
*@contact lunarised@outlook.com
|
||||
*/
|
||||
int mode;
|
||||
void setup() {
|
||||
pinMode(0, INPUT_PULLUP);
|
||||
pinMode (13, OUTPUT);
|
||||
pinMode(8, OUTPUT);
|
||||
Serial.begin (9600); //set up a serial connection with the computer
|
||||
|
||||
pinMode(11, OUTPUT); //the trigger pin
|
||||
pinMode(12, INPUT); //echo pin
|
||||
if (digitalRead(0) ==HIGH){
|
||||
mode = 0;
|
||||
mode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (mode == 0){
|
||||
digitalWrite(13, HIGH);
|
||||
tone(8, getNote());
|
||||
}
|
||||
}
|
||||
float getNote()
|
||||
{
|
||||
float echoTime;
|
||||
float calculatedDistance;
|
||||
digitalWrite(11, HIGH);
|
||||
delayMicroseconds(20);
|
||||
digitalWrite(11, LOW);
|
||||
|
||||
echoTime = pulseIn(12, HIGH);
|
||||
calculatedDistance = echoTime / 8;
|
||||
calculatedDistance += 110;
|
||||
if (calculatedDistance > 1760){ //
|
||||
|
||||
calculatedDistance = 1760;
|
||||
}
|
||||
Serial.print(calculatedDistance); //print units after the distance
|
||||
Serial.println(" hz"); //print units after the distance
|
||||
return calculatedDistance;
|
||||
}
|
Loading…
Reference in New Issue
Block a user