// For: https://forum.arduino.cc/t/control-multiple-leds-by-an-analog-reading-after-going-trhough-an-amplifier/1064318/
// This Wokwi project: https://wokwi.com/projects/350889349735252562
const int ledUH = 8;
const int ledH = 9;
const int ledN = 10;
const int ledL = 11;
const int ledUL = 12;
const int inaPin = A0;
#define ontime 300
#define offtime 200
void setup()
{
// put your setup code here, to run once:
pinMode (ledUH, OUTPUT);
pinMode (ledH, OUTPUT);
pinMode (ledN, OUTPUT);
pinMode (ledL, OUTPUT);
pinMode (ledUL, OUTPUT);
pinMode (inaPin, INPUT);
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
int x = analogRead(inaPin);
float glucoValue = float(x); // try the sketch with a float
Serial.print("Value is: ");
Serial.print(glucoValue,0);
Serial.print(", ");
if( glucoValue <= 170.0)
{
Serial.println("Very low");
digitalWrite (ledUL, HIGH);
delay(ontime);
digitalWrite (ledUL, LOW);
delay(offtime);
}
else if( glucoValue <= 500.0)
{
Serial.println("Low");
digitalWrite (ledL, HIGH);
delay(ontime);
digitalWrite (ledL, LOW);
delay(offtime);
}
else if( glucoValue <= 690.0)
{
Serial.println("Normal");
digitalWrite (ledN, HIGH);
delay(ontime);
digitalWrite (ledN, LOW);
delay(offtime);
}
else if( glucoValue <= 860.0)
{
Serial.println("High");
digitalWrite (ledH, HIGH);
delay(ontime);
digitalWrite (ledH, LOW);
delay(offtime);
}
else
{
Serial.println("Very High");
digitalWrite (ledUH, HIGH);
delay(ontime);
digitalWrite (ledUH, LOW);
delay(offtime);
}
}