Visualize all inputs
This commit is contained in:
parent
5c54d2d48c
commit
0be133e40a
@ -239,8 +239,7 @@ pub fn draw_text<T: DelayNs, DCPin: PinOps, RSTPin: PinOps>(
|
||||
for c in word.chars() {
|
||||
draw_character(display, c, fg, bg, original_x, position, scale);
|
||||
}
|
||||
|
||||
position.x += kerning;
|
||||
draw_character(display, ' ', fg, bg, original_x, position, scale);
|
||||
}
|
||||
position.y += kerning;
|
||||
position.x = original_x;
|
||||
|
66
src/main.rs
66
src/main.rs
@ -11,7 +11,8 @@
|
||||
use core::ptr::addr_of;
|
||||
|
||||
use atmega_hal::{
|
||||
Usart,
|
||||
Adc, Usart,
|
||||
adc::AdcSettings,
|
||||
spi::{self, Settings},
|
||||
usart::Baudrate,
|
||||
};
|
||||
@ -19,9 +20,9 @@ use panic_halt as _;
|
||||
|
||||
use crate::{
|
||||
display::{Display, Rgb565, Vec2},
|
||||
font::{Letter, draw_number, draw_text},
|
||||
graphics::{Image, LARGE_CAT_UNSAFE, PRESS_BTN_UNSAFE, draw_image},
|
||||
peripherals::Button,
|
||||
font::{draw_number, draw_text},
|
||||
graphics::{Image, LARGE_CAT_UNSAFE},
|
||||
peripherals::{Button, Knob},
|
||||
};
|
||||
|
||||
mod display;
|
||||
@ -76,7 +77,12 @@ fn main() -> ! {
|
||||
|
||||
display.init();
|
||||
|
||||
let mut adc = Adc::new(dp.ADC, AdcSettings::default());
|
||||
let mut button = Button::from(pins.pd5.into_pull_up_input());
|
||||
let mut knob = Knob {
|
||||
pin: pins.pc1.into_analog_input(&mut adc),
|
||||
adc,
|
||||
};
|
||||
|
||||
let mut idx = 0;
|
||||
let images = [Image::from(addr_of!(LARGE_CAT_UNSAFE))];
|
||||
@ -85,23 +91,69 @@ fn main() -> ! {
|
||||
let mut position = Vec2 { x: 10, y: 10 };
|
||||
draw_text(
|
||||
&mut display,
|
||||
"how many times can you press the button:\n",
|
||||
"button:\n",
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut position,
|
||||
3,
|
||||
);
|
||||
let button_pos = position.clone();
|
||||
let mut counter = 0;
|
||||
draw_number(
|
||||
&mut display,
|
||||
counter,
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut position.clone(),
|
||||
&mut button_pos.clone(),
|
||||
3,
|
||||
);
|
||||
|
||||
draw_text(
|
||||
&mut display,
|
||||
"\nvolume:\n",
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut position,
|
||||
3,
|
||||
);
|
||||
|
||||
let volume_pos = position.clone();
|
||||
let mut last_volume = knob.raw();
|
||||
let mut counter = 0;
|
||||
draw_number(
|
||||
&mut display,
|
||||
last_volume.into(),
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut volume_pos.clone(),
|
||||
3,
|
||||
);
|
||||
|
||||
loop {
|
||||
let volume = knob.raw();
|
||||
if volume != last_volume {
|
||||
if volume == 0 || last_volume == 0 || last_volume.ilog10() > volume.ilog10() {
|
||||
// Clear previous
|
||||
draw_text(
|
||||
&mut display,
|
||||
" ",
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut volume_pos.clone(),
|
||||
3,
|
||||
);
|
||||
}
|
||||
last_volume = volume;
|
||||
draw_number(
|
||||
&mut display,
|
||||
volume.into(),
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut volume_pos.clone(),
|
||||
3,
|
||||
);
|
||||
}
|
||||
|
||||
if button.poll() {
|
||||
counter += 1;
|
||||
draw_number(
|
||||
@ -109,7 +161,7 @@ fn main() -> ! {
|
||||
counter,
|
||||
Rgb565::white(),
|
||||
Rgb565::black(),
|
||||
&mut position.clone(),
|
||||
&mut button_pos.clone(),
|
||||
3,
|
||||
);
|
||||
// match draw_image(
|
||||
|
@ -51,7 +51,10 @@ where
|
||||
Pin<mode::Analog, T>: AdcChannel<Atmega, ADC>,
|
||||
{
|
||||
pub fn poll(&mut self) -> f32 {
|
||||
let read = self.pin.analog_read(&mut self.adc);
|
||||
read as f32 / 1024f32
|
||||
self.raw() as f32 / 1024f32
|
||||
}
|
||||
|
||||
pub fn raw(&mut self) -> u16 {
|
||||
self.pin.analog_read(&mut self.adc)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user