Soldering the wires in place, smooth process, did it in one tryðŸ¤
The sound was too low, I had to adjust the ranges and one of the instructors advised me to connect the black ground wire leg of the speaker directly to the ground without the resistor.
void setup() {
//
}
void loop() {
// get a sensor reading:
int sensorReading = analogRead(A0);
// map the results from the sensor reading's range
// to the desired pitch range:
float frequency = map(sensorReading, 200, 600, 300, 800); // was reading (00, 600, 100, 1000)
// change the pitch, play for 10 ms:
tone(8, frequency, 10);
delay(10);
}
// it was reading (00, 600, 100, 1000) before
Since the threshold was too low, I was getting notes when it wasn’t pressed, and the value when there was no force still went above the threshold. FSRs are funny, they either don’t stay in the breadboard, specially if the board has been successfully pierced to fit other wires, or could read unwanted force like in this case 😅
#include "pitches.h"
const int threshold = 10; // minimum reading of the sensors that generates a note
const int speakerPin = 8; // pin number for the speaker
const int noteDuration = 20; // play notes for 20 ms
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C3 };
void setup() {
}
void loop() {
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
// get a sensor reading:
int sensorReading = analogRead(thisSensor);
// if the sensor is pressed hard enough:
if (sensorReading > threshold) { //It plays after the treshhold
// play the note corresponding to this sensor:
tone(speakerPin, notes[thisSensor], noteDuration);
delay(noteDuration); //start a new note during that duration
}
}
}