Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. use rust_gpiozero::*;
  2. use std::{
  3. fs::File,
  4. thread,
  5. time,
  6. }
  7.  
  8. const PIN: u8 = 17;
  9. const FILE_TEMP: &str = "/sys/class/thermal/thermal_zone0/temp";
  10. const SLEEP_T: usize = 5; // 5 seconds
  11.  
  12. fn main() {
  13.  
  14. let fan_pin = output_devices::OutputDevice::new(PIN);
  15.  
  16. loop {
  17. let mut file = File::open(FILE_TEMP)?;
  18. let mut contens = String::new();
  19.  
  20. file.read_to_string(&mut contents)?;
  21.  
  22. let temperature: u8 = contents.parse()?;
  23.  
  24. if (temperature < MIN_TEMP && fan_pin.value() || temperature > MAX_TEMP && !fan_pin.value()) {
  25. fan_pin.toggle();
  26. }
  27.  
  28. thread::sleep(time::Duration::from_secs(SLEEP_T))
  29. }
  30. led.blink(2.0,3.0);
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement