#include <WiFi.h>
#define Button 0
#define LED 2
#define Microphone 15
bool isRecording = false;
void setup() {
Serial.begin(9600);
Serial.print("Connecting to WiFi");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
pinMode(Button, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(Microphone, INPUT);
}
void readSound(){
if (isRecording){
int sample = analogRead(Microphone);
Serial.println(sample);
digitalWrite(13, abs(sample - 512) > 50);
}
}
void loop() {
delay(100); // this speeds up the simulation
// Button press detection
if (digitalRead(Button) == LOW && !isRecording) {
Serial.println("Button Pressed, Start Recording...");
isRecording = true;
}
// Button release detection
if (digitalRead(Button) == HIGH && isRecording) {
Serial.println("Button Released, Stop Recording...");
isRecording = false;
}
readSound();
}