// We have used two potentiometer in this simulation each assuming to collect audio signals
// This signals are used to calculate emotions.
// we have also added a button to check human presence that is if that button is clicked
// means that they is no human presence.
const int POT1_PIN = 36;
const int POT2_PIN = 39;
const int BUTTON_PIN = 4;
const float EMOTION_RANGES[5][2] = {
{0.0, 0.6},
{0.6, 1.2},
{1.2, 1.8},
{1.8, 2.4},
{2.4, 3.3}
};
const String EMOTIONS[5] = {
"Happiness",
"Sadness",
"Anger",
"Surprise",
"Neutral"
};
float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
String getEmotion(float voltage) {
for (int i = 0; i < 5; i++) {
if (voltage >= EMOTION_RANGES[i][0] && voltage < EMOTION_RANGES[i][1]) {
return EMOTIONS[i];
}
}
return "Unknown";
}
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
bool buttonPressed = digitalRead(BUTTON_PIN) == LOW;
if (buttonPressed) {
int pot1Value = analogRead(POT1_PIN);
int pot2Value = analogRead(POT2_PIN);
float voltage1 = floatMap(pot1Value, 0, 4095, 0, 3.3);
float voltage2 = floatMap(pot2Value, 0, 4095, 0, 3.3);
float averageVoltage = (voltage1 + voltage2) / 2.0;
String emotion = getEmotion(averageVoltage);
Serial.print("Potentiometer 1 Voltage: ");
Serial.print(voltage1);
Serial.print(", Potentiometer 2 Voltage: ");
Serial.print(voltage2);
Serial.print(", Average Voltage: ");
Serial.print(averageVoltage);
Serial.print(", Emotion: ");
Serial.println(emotion);
} else {
//If button is pressed it means humans are not detected so it potentiometer wont display any emotion
Serial.println("Human not detected");
}
delay(1000);
}