chore: Remove unused main.rs
This commit is contained in:
parent
797ab60b8b
commit
5b1decf4a4
1 changed files with 0 additions and 39 deletions
39
src/main.rs
39
src/main.rs
|
|
@ -1,39 +0,0 @@
|
||||||
use core::f64;
|
|
||||||
use std::f64::consts::TAU;
|
|
||||||
use std::thread;
|
|
||||||
use std::time::{Duration, Instant};
|
|
||||||
|
|
||||||
use rppal::pwm::{Channel, Polarity, Pwm};
|
|
||||||
|
|
||||||
/// 1 kHz PWM frequency
|
|
||||||
const PWM_FREQUENCY: f64 = 1000.;
|
|
||||||
|
|
||||||
fn triangle_wave(t: f64) -> f64 { (t - (t + 0.5).floor()).abs() * 2. }
|
|
||||||
fn sine_wave(t: f64) -> f64 { (f64::sin(TAU * t) + 1.) * 0.5 }
|
|
||||||
fn square_wave(t: f64, high_time: f64) -> f64
|
|
||||||
{
|
|
||||||
if t - t.floor() < high_time {
|
|
||||||
1.
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
0.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn sawtooth_wave(t: f64) -> f64 { t - t.floor() }
|
|
||||||
|
|
||||||
fn main()
|
|
||||||
{
|
|
||||||
println!("Starting light control");
|
|
||||||
|
|
||||||
let pwm = Pwm::with_frequency(Channel::Pwm0, PWM_FREQUENCY, 0.5, Polarity::Normal, true)
|
|
||||||
.expect("Unable to initialise PWM");
|
|
||||||
|
|
||||||
let start = Instant::now();
|
|
||||||
loop {
|
|
||||||
let time = start.elapsed().as_secs_f64();
|
|
||||||
let brightness = sawtooth_wave(time * 0.5);
|
|
||||||
|
|
||||||
pwm.set_duty_cycle(brightness).unwrap();
|
|
||||||
thread::sleep(Duration::from_millis(5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue