feat(Button): add example to turn on LEDs with buttons A, B and menu#3
feat(Button): add example to turn on LEDs with buttons A, B and menu#3DumontALINE wants to merge 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Arduino/PlatformIO sample that uses the STeaMi onboard buttons (A, B, Menu) to pulse the corresponding RGB LED channel and log to Serial, and switches the project entrypoint to run that sample.
Changes:
- Added
BUTTON/led_on.cppexample implementing button-driven RGB LED pulses with Serial logging. - Updated
src/main.cppto run the newsetup_led_on()/loop_led_on()example. - Set
upload_protocol = dfuinplatformio.ini.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/main.cpp | Switches the selected sample to led_on (but still includes blink.cpp). |
| platformio.ini | Forces DFU as the upload protocol for the environment. |
| BUTTON/led_on.cpp | New example: reads A/B/Menu buttons and pulses red/green/blue LED channels. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -1,10 +1,13 @@ | |||
| #include <Arduino.h> | |||
| #include "../LED/blink.cpp" | |||
There was a problem hiding this comment.
main.cpp now includes both ../LED/blink.cpp and ../BUTTON/led_on.cpp. The README documents that only one sample should be included at a time (comment/uncomment the #include lines), so the blink include should be commented out/removed when switching to led_on to avoid compiling multiple examples together.
| #include "../LED/blink.cpp" | |
| // #include "../LED/blink.cpp" |
| if (digitalRead(A_BUTTON) == LOW) | ||
| { | ||
| Serial.print("A_BUTTON pressed\n"); | ||
| digitalWrite(LED_RED, HIGH); | ||
| delay(200); | ||
| digitalWrite(LED_RED, LOW); | ||
| } |
There was a problem hiding this comment.
This loop triggers repeatedly while a button is held (and can also retrigger due to contact bounce), so a single press can log multiple times and pulse the LED multiple times. If the intent is "one 200ms pulse per press", add edge detection + debouncing (e.g., track previous button states and ignore changes within a debounce window using millis(), or use a debouncing helper/library).
| Serial.print("A_BUTTON pressed\n"); | ||
| digitalWrite(LED_RED, HIGH); | ||
| delay(200); | ||
| digitalWrite(LED_RED, LOW); | ||
| } | ||
| else if (digitalRead(B_BUTTON) == LOW) | ||
| { | ||
| Serial.print("B_BUTTON pressed\n"); | ||
| digitalWrite(LED_GREEN, HIGH); | ||
| delay(200); | ||
| digitalWrite(LED_GREEN, LOW); | ||
| } | ||
| else if (digitalRead(MENU_BUTTON) == LOW) | ||
| { | ||
| Serial.print("MENU_BUTTON pressed\n"); |
There was a problem hiding this comment.
Using Serial.print("...\n") works, but it’s inconsistent with the existing example (blink.cpp) which uses Serial.println(...). Prefer Serial.println("A_BUTTON pressed") / etc. for readability and consistent newline handling.
| Serial.print("A_BUTTON pressed\n"); | |
| digitalWrite(LED_RED, HIGH); | |
| delay(200); | |
| digitalWrite(LED_RED, LOW); | |
| } | |
| else if (digitalRead(B_BUTTON) == LOW) | |
| { | |
| Serial.print("B_BUTTON pressed\n"); | |
| digitalWrite(LED_GREEN, HIGH); | |
| delay(200); | |
| digitalWrite(LED_GREEN, LOW); | |
| } | |
| else if (digitalRead(MENU_BUTTON) == LOW) | |
| { | |
| Serial.print("MENU_BUTTON pressed\n"); | |
| Serial.println("A_BUTTON pressed"); | |
| digitalWrite(LED_RED, HIGH); | |
| delay(200); | |
| digitalWrite(LED_RED, LOW); | |
| } | |
| else if (digitalRead(B_BUTTON) == LOW) | |
| { | |
| Serial.println("B_BUTTON pressed"); | |
| digitalWrite(LED_GREEN, HIGH); | |
| delay(200); | |
| digitalWrite(LED_GREEN, LOW); | |
| } | |
| else if (digitalRead(MENU_BUTTON) == LOW) | |
| { | |
| Serial.println("MENU_BUTTON pressed"); |
| @@ -2,3 +2,4 @@ | |||
| platform = ststm32@^19 | |||
| board = steami | |||
| framework = arduino | |||
There was a problem hiding this comment.
Setting upload_protocol = dfu changes the default upload behavior for the whole project, but the board definition (boards/steami.json) doesn’t list dfu as a supported protocol. Consider either leaving the default protocol alone, or adding a separate environment (e.g. [env:steami_dfu]) so users can opt into DFU without breaking the standard upload flow.
| framework = arduino | |
| framework = arduino | |
| [env:steami_dfu] | |
| extends = env:steami |
|
Bon travail sur cette PR, c’est une bonne base et ça va clairement dans le bon sens pour fournir un exemple Arduino exploitable. Comportement vs issue (point principal)L’issue demande un toggle de LED à chaque appui, alors que l’implémentation actuelle allume simplement la LED pendant 200 ms. Cela ne respecte pas :
Suggestion : ledState[i] = !ledState[i];
digitalWrite(ledPin[i], ledState[i]);Debounce non conformeLe
Suggestion :
Gestion des boutons (else if)L’utilisation de Suggestion : Logs sérieLes Suggestion : Serial.println("A_BUTTON pressed");delay(2000) dans setupLe Suggestion :
Nommage et intentionLe nom du fichier et des fonctions ( Suggestion : Absence d’état des LEDsIl manque une structure pour stocker l’état courant de chaque LED, ce qui empêche de faire un toggle correct. Suggestion : Description de la PRQuelques points d’amélioration côté description :
Dans l’ensemble, c’est du bon travail et la structure est déjà en place. Avec les ajustements sur le toggle et le debounce, la PR sera parfaitement alignée avec l’issue. |
…naming and serial logs.
close #1
This code allows you to control the RGB LED of the STeaMi board using the three onboard buttons.
Each LED stays on for 200ms when its corresponding button is pressed, and each interaction is logged to the serial consoleHow to test
1 Flash the firmware onto the STEAMI board via PlatformIO
2 Open the serial monitor at 115200 baud
3 Press button A — the red LED should toggle on, press again and it should toggle off
4 Press button B — the green LED should toggle on, press again and it should toggle off
5 Press the MENU button — the blue LED should toggle on, press again and it should toggle off
7 Hold a button down and verify the LED toggles only once and does not flicker
8 Press multiple buttons and verify multiple LEDs can be on at the same time
Checklist