#![no_std]
#![no_main]
use panic_halt as _;
use esp32_hal::prelude::*;
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
use embedded_graphics::prelude::*;
use embedded_graphics::mono_font::{MonoTextStyle, ascii::Font6x9};
use embedded_graphics::text::Text;
use esp32_hal::delay::Delay;
#[entry]
fn main() -> ! {
let peripherals = esp32_hal::pac::Peripherals::take().unwrap();
let mut delay = Delay::new(&peripherals.TIMG0);
// Mock pins
let mut led1 = MockOutput::new();
let mut led2 = MockOutput::new();
let mut led3 = MockOutput::new();
let button1 = MockInput::new();
let button2 = MockInput::new();
let button3 = MockInput::new();
let mut servo = MockPwm::new();
let mut buzzer = MockOutput::new();
let mut pot1 = 2048u16;
let mut pot2 = 1024u16;
let mut pot3 = 3072u16;
// Mock I2C and OLED
let interface = I2CDisplayInterface::new(MockI2C::new());
let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0)
.into_buffered_graphics_mode();
display.init().unwrap();
let style = MonoTextStyle::new(&Font6x9, BinaryColor::On);
loop {
// Update mock pot values (simulate ADC)
pot1 = (pot1 + 10) % 4096;
pot2 = (pot2 + 15) % 4096;
pot3 = (pot3 + 20) % 4096;
// Update LEDs based on pot values
led1.set_duty((pot1 as u32 * 100 / 4095) as u8);
led2.set_duty((pot2 as u32 * 100 / 4095) as u8);
led3.set_duty((pot3 as u32 * 100 / 4095) as u8);
// Servo angle simulation
servo.set_duty((pot1 as u32 * 100 / 4095) as u8);
// Buttons / buzzer logic
if button1.is_pressed() || button2.is_pressed() || button3.is_pressed() {
buzzer.set_high();
} else {
buzzer.set_low();
}
// OLED display update
display.clear();
Text::new(
&format!("Pot1:{}\nPot2:{}\nPot3:{}\nServo:{}",
pot1, pot2, pot3, (pot1 as u32 * 100 / 4095)),
Point::new(0, 0),
style,
).draw(&mut display).unwrap();
display.flush().unwrap();
delay.delay_ms(100u16);
}
}
// --------------------
// Mock structures for Wokwi
// --------------------
struct MockOutput;
impl MockOutput {
fn new() -> Self { MockOutput }
fn set_high(&mut self) {}
fn set_low(&mut self) {}
fn set_duty(&mut self, _val: u8) {}
}
struct MockInput;
impl MockInput {
fn new() -> Self { MockInput }
fn is_pressed(&self) -> bool { false }
}
struct MockPwm;
impl MockPwm {
fn new() -> Self { MockPwm }
fn set_duty(&mut self, _val: u8) {}
}
struct MockI2C;
impl MockI2C {
fn new() -> Self { MockI2C }
}