Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the ignition domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /dom953964/wp-includes/functions.php on line 6131

Deprecated: Return type of GD_WordPress_File_Iterator_Filter::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /dom953964/wp-content/plugins/wp_migration-master/classes/iterators.php on line 5

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the health-check domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /dom953964/wp-includes/functions.php on line 6131
Pitch Follower with Button and Smoothing – Lara Grant

Pitch Follower with Button and Smoothing

[code lang=”arduino” light=”true”]
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status

const int numReadings = 10; //average 10 values

int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

int inputPin = A6;

void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;

}

void loop() {
//read the button and store it’s state in new variable
buttonState = digitalRead(buttonPin);

// subtract the last reading:
total= total – readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;

// if we’re at the end of the array…
if (index >= numReadings)
// …wrap around to the beginning:
index = 0;

// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);

// map the pitch to the range of the analog input.
// change the minimum and maximum input numbers below
// depending on the range your sensor’s giving:
int thisPitch = map(average, 30, 0, 100, 1000);

// if button in pressed do this…
if (buttonState == LOW){

// play the pitch:
tone(7, thisPitch, 10);

delay(1); // delay in between reads for stability
}

}
[/code]

Leave a Reply