Skip to content

Commit

Permalink
ldr draft
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplFerris committed Nov 13, 2024
1 parent d6e3a48 commit e54efb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@
- [got module](./buzzer/got-module.md)
- [Play](./buzzer/play.md)
- [Active Beep](./buzzer/active-beep.md)
- [LDR](./ldr/index.md)
- [ADC](./ldr/adc.md)
- [LDR and LED](./ldr/ldr-led.md)


- [Resources](./resources.md)
3 changes: 3 additions & 0 deletions src/ldr/adc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ADC (Analog to Digital Converter)

# TODO: Explanation
3 changes: 3 additions & 0 deletions src/ldr/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## LDR (Light Dependent Resistor)

# TODO: Explanation
34 changes: 34 additions & 0 deletions src/ldr/ldr-led.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Turn on LED(or Lamp) in low Light with Pico

In this exercise, we'll control an LED based on ambient light levels. The goal is to automatically turn on the LED in low light conditions.

You can try this in a closed room by turning the room light on and off. When you turn off the room-light, the LED should turn on, given that the room is dark enough, and turn off again when the room-light is switched back on. Alternatively, you can adjust the sensitivity threshold or cover the light sensor (LDR) with your hand or some object to simulate different light levels.

Note: You may need to adjust the ADC threshold based on your room's lighting conditions and the specific LDR you are using.

# TODO: Explanation

```rust
bind_interrupts!(struct Irqs {
ADC_IRQ_FIFO => InterruptHandler;
});

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut adc = Adc::new(p.ADC, Irqs, Config::default());

let mut p26 = Channel::new_pin(p.PIN_26, Pull::None);
let mut led = Output::new(p.PIN_15, Level::Low);

loop {
let level = adc.read(&mut p26).await.unwrap();
if level > 3800 {
led.set_high();
} else {
led.set_low();
}
Timer::after_secs(1).await;
}
}
```

0 comments on commit e54efb7

Please sign in to comment.