How to read a connection for a serial?

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?

Please read Forum Code Formatting and Syntax Highlighting and edit your prior post by using the pencil-shaped edit button under that post. Note that you can specify the language syntax to be used in highlighting by specifying the language at the end of the first row of three backticks. (Rust is the default language if you don't specify toml or c++ or something else.)

As you can see from the above post, many readers of this forum will ignore code snippets, compiler error reports, etc that do not follow the posting guidelines for new contributors that are pinned to the top of this forum. Even those who do respond may feel that the lack of following the forum posting guidelines is disrespectful of their time. Thanks. :clap:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.