Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use rust_gpiozero::*;
- use std::{
- fs::File,
- thread,
- time,
- }
- const PIN: u8 = 17;
- const FILE_TEMP: &str = "/sys/class/thermal/thermal_zone0/temp";
- const SLEEP_T: usize = 5; // 5 seconds
- fn main() {
- let fan_pin = output_devices::OutputDevice::new(PIN);
- loop {
- let mut file = File::open(FILE_TEMP)?;
- let mut contens = String::new();
- file.read_to_string(&mut contents)?;
- let temperature: u8 = contents.parse()?;
- if (temperature < MIN_TEMP && fan_pin.value() || temperature > MAX_TEMP && !fan_pin.value()) {
- fan_pin.toggle();
- }
- thread::sleep(time::Duration::from_secs(SLEEP_T))
- }
- led.blink(2.0,3.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement