working pressing and blinking

This commit is contained in:
Filipriec
2025-10-09 19:05:16 +02:00
parent 34eedd3e1f
commit de1b818732
2 changed files with 29 additions and 12 deletions

View File

@@ -1,4 +1,7 @@
mbed-tools compile -m NUCLEO_U575ZI_Q -t GCC_ARM
probe-rs:
sudo probe-rs run --chip STM32U575ZI cmake_build/NUCLEO_U575ZI_Q/develop/GCC_ARM/mbed-os-example-blinky.elf
sudo probe-rs gdb --chip STM32U575ZI --protocol swd
arm-none-eabi-gdb cmake_build/NUCLEO_U575ZI_Q/develop/GCC_ARM/mbed-os-example-blinky.elf

View File

@@ -1,7 +1,4 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
// main.cpp
#include "mbed.h"
@@ -12,20 +9,37 @@
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalIn tlacitko(Button1);
DigitalIn button(PC_13);
void set_led_pattern(int pattern) {
switch (pattern) {
case 0:
led1 = 1; led2 = 0; led3 = 0;
break;
case 1:
led1 = 0; led2 = 1; led3 = 0;
break;
case 2:
led1 = 0; led2 = 0; led3 = 1;
break;
}
}
int main()
{
tlacitko.mode(PullNone);
int pattern = 0;
set_led_pattern(pattern);
while (true) {
led1 = 1; led2 = 0; led3 = 0;
ThisThread::sleep_for(BLINKING_RATE);
if (button == 0){
pattern = (pattern + 1) % 3;
set_led_pattern(pattern);
led1 = 0; led2 = 1; led3 = 0;
ThisThread::sleep_for(BLINKING_RATE);
while (button == 0) {
ThisThread::sleep_for(10ms);
}
led1 = 0; led2 = 0; led3 = 1;
ThisThread::sleep_for(BLINKING_RATE);
ThisThread::sleep_for(150ms);
}
}
}