Browse Source

Remove costly unwrap from example

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
trying.tmp
Daniel Egger 3 years ago
parent
commit
6c1420e0d1
  1. 12
      examples/blinky_adc.rs

12
examples/blinky_adc.rs

@ -33,11 +33,13 @@ fn main() -> ! {
loop {
led.toggle().ok();
let val: u16 = adc.read(&mut an_in).unwrap();
/* shift the value right by 3, same as divide by 8, reduces
the 0-4095 range into something approximating 1-512 */
let time: u16 = (val >> 3) + 1;
let time: u16 = if let Ok(val) = adc.read(&mut an_in) as Result<u16, _> {
/* shift the value right by 3, same as divide by 8, reduces
the 0-4095 range into something approximating 1-512 */
(val >> 3) + 1
} else {
1000
};
delay.delay_ms(time);
}

Loading…
Cancel
Save