Formatted and Commented Code

This commit is contained in:
James McKenzie 2019-04-29 22:22:16 +12:00
parent deb63bfb07
commit b76067d67a

View File

@ -3,18 +3,16 @@
*@lang C89 Based
*@contact lunarised@outlook.com
*/
int mode;
int mode;
void setup() {
pinMode(6, INPUT_PULLUP);
pinMode (13, OUTPUT);
pinMode(8, OUTPUT);
pinMode (7, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
Serial.begin (9600); //set up a serial connection with the computer
pinMode(11, OUTPUT); //the trigger pin
pinMode(12, INPUT); //echo pin
pinMode(6, INPUT_PULLUP); //Mode Select Pin
pinMode (13, OUTPUT); //LED Indicator Pin
pinMode(8, OUTPUT); //Speaker Pin
pinMode (7, INPUT_PULLUP); //Play Pin
pinMode(5, INPUT_PULLUP); //+Octave Play Pin
Serial.begin (9600); //Set up a Serial Connection
pinMode(11, OUTPUT); //Trigger pin
pinMode(12, INPUT); //Echo pin
}
@ -39,32 +37,37 @@ void loop() {
Serial.print(note); //print frequency
Serial.println(" hz"); //print units after frequency
tone(8, note);
}
else{
noTone(8);
}
}
/*
* Method that uses an UltraSonic sensor to calculate a frequency
* @return A Frequency generated by a sensor
*/
float 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){ //git
calculatedDistance = 1760;
calculatedDistance = echoTime / 8; //Change this value to decrease
//the playing physical range
calculatedDistance += 110; //Minimum value
if (calculatedDistance > 1760){ //Prevent high pitched sounds
calculatedDistance = 1760; //Maximum Value
}
return calculatedDistance;
}
/*
* Method which takes a note, and brings the note down to a correct pitch
* @param toTune The Note in which you are autotuning
* @return The Note that has now been autotuned
*/
float tune(float toTune){
if (toTune> 523.75){ //C5
return 523.75;