#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
#define GLUCOSE_SENSOR_PIN 34 // Analog pin connected to the glucose sensor
#define ledVerde 15 // Led Normal
#define ledAmarillo 2 // Led Alerta
#define ledRojo 4 // Led Peligro
void setup() {
Serial.begin(115200); // Initialize serial communication
pinMode(ledVerde, OUTPUT);
pinMode(ledAmarillo, OUTPUT);
pinMode(ledRojo, OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop() {
// Read glucose level from sensor
int glucoseLevel = analogRead(GLUCOSE_SENSOR_PIN);
int glucosaMap = map(glucoseLevel, 0, 4096, 0, 300);
// Send glucose level data to ThingSpeak
// Send glucose level data over UART to Raspberry Pi Pico
Serial.print("Glucose Level: ");
Serial.println(glucoseLevel);
/*
En ayunas (8 horas sin comer):
Nivel normal: 70-99 mg/dL
Nivel prediabético: 100-125 mg/dL
Diabetes: 126 mg/dL o más
*/
if (glucosaMap >= 70 && glucosaMap <= 99 ) digitalWrite(ledVerde, HIGH);
else digitalWrite(ledVerde, LOW);
if (glucosaMap >= 100 && glucosaMap <= 125 ) digitalWrite(ledAmarillo, HIGH);
else digitalWrite(ledAmarillo, LOW);
if (glucosaMap >= 126 || glucosaMap <= 69 ) digitalWrite(ledRojo, HIGH);
else digitalWrite(ledRojo, LOW);
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Nivel de glucosa"); // print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (2, 1)
lcd.print(glucosaMap); // print message at (2, 1)
delay(2000); // display the above for two seconds
}