HLUZ7QUVMCB4THRXBCW5RNTI463RYY4NLOTQHWTOWFLLA7IIWSGAC
/*
* For examples (and inspiration), head to
*
* https://github.com/Rahix/avr-hal/tree/main/examples
*
* NOTE: Not all examples were ported to all boards! There is a good chance though, that code
* for a different board can be adapted for yours. The Arduino Uno currently has the most
* examples available.
*/
#[cfg(debug_assertions)]
macro_rules! log {
() => {
uwwriteln!(&mut serial).unwrap();
};
($($arg:tt)*) => {{
uwriteln!(&mut serial, $($arg)*).unwrap();
}};
}
led.toggle();
arduino_hal::delay_ms(1000);
log!("Start of loop!");
log!("Read sensor value");
let sensor = a0.analog_read(&mut adc);
log!("sensor = {}", sensor);
let r2 = r1 * MAX_ANALOG_VALUE / u32::from(sensor) - r1;
stack.push(r2).unwrap();
if stack.is_full() {
log!("Stack is full!");
log!("Add up stack");
let sum: u32 = stack.iter().sum();
let average = sum / 10;
log!("average = {}", average);
if r1.abs_diff(average) > R_SMALL.abs_diff(average) {
r1 = R_SMALL;
relay.set_high();
arduino_hal::delay_ms(1000);
} else {
r1 = 9870;
relay.set_low();
arduino_hal::delay_ms(1000);
uwriteln!(&mut serial, "R2: {}", average).unwrap();
}
stack.clear();
}