const int buttonPin1 = 25;
const int buttonPin2 = 26;
int buttonState1 = 0;
int buttonState2 = 0;
int lastButtonState1 = 0;
int lastButtonState2 = 0;
void setup() {
Serial.begin(9600);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
Serial.println("I'm alive");
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH && lastButtonState1 == LOW) {
Serial.println("Button 1 pressed!");
}
if (buttonState2 == HIGH && lastButtonState2 == LOW) {
Serial.println("Button 2 pressed!");
}
lastButtonState1 = buttonState1;
lastButtonState2 = buttonState2;
delay(50);
}
Following the button fiasco, I decided to go ahead and move to working with a speaker module. According to the datasheet that came with
it on Amazon, it was a digital input and so it would only give 0 and 1 as outputs (there is a sound or not).
The first of
the two speakers I purchsed seemed to have a short within it as it always got very hot when I plugged it in, so I switched to the other one.
At first, I was only able to get 0 values but then I talked with
Charlie and found out the penetiometer on the speaker can actually be rotated! Then I was able to calibrate the output. The code to make this portion function was actually very simple.
int soundValue = analogRead(soundPin);
Serial.println(soundValue);
. . , .
!!
00
01
02
03
04
05
06
07
08
09
10
11
12
??