I'm making a code so i can turn on and off a led using a bluetooth app and a bluetooth device. The point is if i choose a letter, the led turns on, and if i use another, it turns off. I already advanced it but i'm stuck with how can i do to make the card to recieve the signal. I found a portion of the code i need but it's for an arduino and i need it in Rust. Can anyone help me translate it?
This is my code
fn main() -> ! {
let dp = stm32::Peripherals::take().unwrap();
let cp = cortex_m::peripheral::Peripherals::take().unwrap();
let gpioa = dp.GPIOA.split();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.use_hse(8.mhz()).freeze();
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);
//define pins
let tx_pin = gpioa.pa9.into_alternate_af7();
let rx_pin = gpioa.pa10.into_alternate_af7();
let mut led_pin = gpioa.pa7.into_push_pull_output();
// configure serial
let serial = Serial::usart1(
dp.USART1,
(tx_pin, rx_pin),
Config::default().baudrate(9600.bps()),
clocks,
).unwrap();
let (mut _tx, mut rx) = serial.split();
let mut state = 0;
loop {
if state == 'a' {
led_pin.set_high().unwrap();
}
if state == 'b' {
led_pin.set_low().unwrap();
}
}
}
This is what i used to build the code
int led=13;
int state=0;
void setup(){
Serial.begin(9600);
pinMode(led,OUTPUT);
}
void loop(){
if (Serial.available()>0){
state = Serial.read();
}
if (state == 'a'){
digitalWrite(led,'HIGH');
}
if (state == 'b'){
digitalWrite(led,'LOW');
}
}
Can anyone tell me how to implement it correctly or what am i missing?