// 定時器中斷 (10ms)
void TIM2_IRQHandler(void) {
if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) {
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
UpdateLEDs();
ProcessKey();
}
}作者: 單片機重購 時間: 2025-6-27 14:47
這種的程序網上開源的很多,你需要去網上找找,在這個網站學習STM32完全不夠用的哦,你要去別的網站再去搜尋點STM32的資料哦作者: SHYKH 時間: 2025-6-27 17:21
Hi! Your project sounds like a fun and practical challenge—controlling 8 LEDs with multiple switching patterns using a button, and even syncing with a buzzer for bonus points. I'd be happy to offer some ideas to help you get started. ✅ Suggested Approach: 🔁 1. Use a Microcontroller (like Arduino or STM32): It’s the easiest way to handle multiple LEDs, button input, and a buzzer with flexible logic. 🔘 2. Button-Control Logic: Use one button to cycle through 4 different modes. Each press can increment a mode counter (0–3), and after the 4th, reset back to 0. c Copy Edit // Pseudocode for button press logic if (buttonPressed) { mode = (mode + 1) % 4; } 💡 LED Pattern Ideas (at least 4): All LEDs ON Chase effect (like running lights, one LED on at a time in sequence) Blink all LEDs together Even/Odd pattern (alternate between even-numbered and odd-numbered LEDs) 🔔 Bonus: Add Buzzer Coordination You can sync a short beep with every button press or Make the buzzer follow the LED pattern (e.g., beep when LEDs blink) c Copy Edit // Example: Turn on buzzer with LED digitalWrite(buzzerPin, HIGH); delay(100); digitalWrite(buzzerPin, LOW); 🧠 Additional Tips: Use debounce logic or delay() after button press to avoid false triggers. Store the mode state in a variable and use a switch or if statements to control LED patterns. You could even add PWM dimming if you want to level up! Let me know what platform or microcontroller you’re using—I’d be glad to share example code or schematics tailored to your setup. Good luck with your design!作者: ICMAN 時間: 2025-6-30 13:38
硬件可以用SC09B觸摸芯片來實現觸摸按鍵、觸摸滑條滾輪的任意組合控制燈光開關和功能效果的切換~