int main(void) { int i; int switch_state;

gpio_init(LIGHT_BLUE,GPIO_OUTPUT,LIGHT_OFF);
gpio_init(SWITCH_CTRL,GPIO_INPUT,0);
gpio_pull(SWITCH_CTRL,PULL_UP);

for(;;)
{
    switch_state = gpio_read(SWITCH_CTRL); // read switch state
    
    if(switch_state == 0) // if switch is pressed
    {
        gpio_write(LIGHT_BLUE, LIGHT_ON); // turn on light
    }
    else // if switch is not pressed
    {
        gpio_write(LIGHT_BLUE, LIGHT_OFF); // turn off light
    }
}
int mainvoid int i; gpio_initLIGHT_BLUEGPIO_OUTPUTLIGHT_OFF; gpio_initSWITCH_CTRLGPIO_INPUT0; gpio_pullSWITCH_CTRLPULL_UP; for;; 添加代码用开关控制灯

原文地址: https://www.cveoy.top/t/topic/cOcU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录