#include "SSD1306.h"
SSD1306 display(0x3c, 4, 5);
// SH1106 display(0x3c, D3, D5);
int Output_control_1 = 10; // set control pin is pin10;
int Output_control_2 = 13; // set control pin is pin13;
int V_level_1 = LOW;
int V_level_2 = LOW;
int voiceValue = 0; // variable to store the read value
void setup() {
pinMode(Output_control_1, OUTPUT);
pinMode(Output_control_2, OUTPUT);
Serial.begin(115200);
Serial.println();
Serial.println();
// Initialising the UI will init the display too.
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Voice sensor"); //write "sensordiode in OLED when it's start.
display.display();
}
void loop() {
display.clear();
voiceValue = analogRead(A0); // read the input pin
display.drawString(0, 0, "Voice val =" + String(voiceValue));
if ( voiceValue < 23){
V_level_1 = HIGH;
V_level_2 = LOW;
}
else if ( (voiceValue >=23) && (voiceValue <= 25) ) {
V_level_1 = LOW;
V_level_2 = HIGH;
}
else {
V_level_1 = HIGH ;
V_level_2 = HIGH;
}
digitalWrite(Output_control_1, V_level_1);
digitalWrite(Output_control_2, V_level_2);
display.display();
delay(1);
}