#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/gpio.h"
#define DHT_PIN 26
#define LED_PIN 25
#define FAN_PIN 15 // simulate fan with green LED
#define AC_PIN 14 // simulate AC with red LED
// Simulated temperature reading
float read_temperature() {
static float temp = 25.0f;
temp += 1.0f;
if (temp > 40.0f) temp = 25.0f;
return temp;
}
int main() {
stdio_init_all();
// Initialize pins
gpio_init(LED_PIN); gpio_set_dir(LED_PIN, true);
gpio_init(FAN_PIN); gpio_set_dir(FAN_PIN, true);
gpio_init(AC_PIN); gpio_set_dir(AC_PIN, true);
while (1) {
float temperature = read_temperature();
printf("Temperature: %.2f C\n", temperature);
// Blink system LED
gpio_put(LED_PIN, 1);
sleep_ms(200);
gpio_put(LED_PIN, 0);
// Mutually exclusive control
if (temperature < 28.0f) {
// Low temp → AC ON, Fan OFF
gpio_put(AC_PIN, 1);
gpio_put(FAN_PIN, 0);
} else {
// High temp → Fan ON, AC OFF
gpio_put(AC_PIN, 0);
gpio_put(FAN_PIN, 1);
}
sleep_ms(2000);
}
}