'How do I assign a input pin and an output pin for a led and a button?

I'm trying to make a program in which I use a button to turn on and off a led. The problem is that I don't know how to assign the pins as input for the button and output for the led. I know there is a sentence that says "into_push_pull_output();" but I dont know if I can use this one for the button too because this one says output.

Is the way that I assigned the pins correct or how do I assign a pin for an input and another pin for an output?

#![deny(unsafe_code)]
#![allow(clippy::empty_loop)]
#![no_main]
#![no_std]

//Halt on panic
use panic_halt as _; // panic handler

use cortex_m_rt::entry;
use stm32f4xx_hal as hal;

use crate::hal::{pac, prelude::*};

#[entry]
fn main() -> ! {
    //Access to stm32 peripherals
    if let (Some(dp), Some(cp)) = (
        stm32::Peripherals::take(),
        cortex_m::peripheral::Peripherals::take(),
    ) {
        //Set up the LED and BUTTON. On the Nucleo-446RE it's connected to pin PA5
        let gpioa = dp.GPIOA.split();
        let led = gpioa.pa5.into_push_pull_output();
        let button = gpioa.pa6.into_push_pull_output();

        //Set up system clock
        let rcc = dp.RCC.constrain();
        let clocks = rcc.cfgr.sysclk(48.mhz()).freeze();

        //Create delay abstraction based on SysTick
        let mut delay = hal::delay::Delay::new(cp.SYST, &clocks);
    }

    loop {}
}


Solution 1:[1]

into_floating_input() will create an input pin. If you need to enable the internal pullup resistor or pulldown resistor, you can use the corresponding into_pull_down_input() or into_pull_up_input().

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lkolbly