1
Fork 0

two distance sensors

This commit is contained in:
Andy Killorin 2025-01-07 22:50:36 -05:00
parent c21b033c48
commit 1c04cf8346
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -9,6 +9,7 @@ mod vl53l0;
use core::array;
use core::borrow::BorrowMut;
use core::cell::RefCell;
use core::fmt::Formatter;
use core::panic::PanicInfo;
use core::str::from_utf8;
@ -17,6 +18,7 @@ use bt_hci::cmd::info;
use cyw43_pio::PioSpi;
use embassy_rp::i2c::{Async, I2c};
use embassy_rp::pwm::{self, Pwm};
use embedded_hal_bus::i2c::RefCellDevice;
use fixed::FixedU16;
use log::*;
//use embassy_rp::i2c::InterruptHandler;
@ -95,10 +97,23 @@ async fn main(spawner: Spawner) {
let scl = p.PIN_27;
let config = embassy_rp::i2c::Config::default();
let bus1 = embassy_rp::i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, config);
let bus1 = RefCell::new(bus1);
let mut tof = vl53l0x::VL53L0x::new(bus1).unwrap();
info!("made RefCell");
let mut tof2on = Output::new(p.PIN_16, Level::Low);
info!("2");
Timer::after_millis(1).await;
let mut tof = vl53l0x::VL53L0x::new(RefCellDevice::new(&bus1)).unwrap();
info!("3");
tof.set_address(0x32).unwrap();
info!("4");
tof2on.set_high();
Timer::after_millis(13).await;
info!("5");
let mut tof2 = vl53l0x::VL53L0x::new(RefCellDevice::new(&bus1)).unwrap();
info!("6");
tof.start_continuous(0).unwrap();
let mut gyro = Mpu6050::new_with_addr(bus,0x68);
@ -114,8 +129,12 @@ async fn main(spawner: Spawner) {
//info!("pos: {}", gyro.get_gyro().unwrap().x);
//info!("jerk: {}", gyro.get_acc().unwrap().x);
//info!("temp: {}", gyro.get_temp().unwrap() * (9./5.) + 32.);
if let Ok(dist) = tof.read_range_mm() {
info!("dist: {dist}mm");
if let Ok(dist) = tof.read_range_single_millimeters_blocking() {
info!("dist1: {dist}mm");
}
Timer::after_millis(3).await;
if let Ok(dist) = tof2.read_range_single_millimeters_blocking() {
info!("dist2: {dist}mm");
}
Timer::after_millis(23).await;
}