-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattery.rs
More file actions
50 lines (40 loc) · 1.48 KB
/
Copy pathbattery.rs
File metadata and controls
50 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#![no_std]
#![no_main]
use esp_hal::analog::adc::{Adc, AdcConfig, Attenuation};
use esp_hal::clock::CpuClock;
use esp_hal::delay::Delay;
use esp_hal::gpio::Level::High;
use esp_hal::gpio::{Output, OutputConfig};
use esp_hal::main;
use log::info;
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
extern crate alloc;
#[main]
fn main() -> ! {
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 72 * 1024);
let delay = Delay::new();
// turn on the board power
let mut board_power = Output::new(peripherals.GPIO10, High, OutputConfig::default());
board_power.set_high();
delay.delay_millis(1000);
info!("running");
let analog_pin = peripherals.GPIO4;
let mut adc_config = AdcConfig::new();
let mut pin = adc_config.enable_pin(analog_pin, Attenuation::_11dB);
let mut adc1 = Adc::new(peripherals.ADC1, adc_config);
loop {
info!("getting the pin value");
let pin_value: u16 = adc1.read_blocking(&mut pin);
info!("bat adc is {pin_value} ");
delay.delay_millis(1500);
}
}