const int ledPins[] = {PB0, PB1, PB2, PB3, PB4, PB5};
const int numLeds = 6;
// Пины кнопок
const int btn1Pin = PA0; // Увеличить скорость
const int btn2Pin = PA1; // Уменьшить скорость
volatile unsigned long animationDelay = 300;
volatile unsigned long lastInterruptTime = 0;
const unsigned long debounceDelay = 300;
const byte patterns[12] = {
B000000, // 1. ○○○○○○
B000001, // 2. ●○○○○○ (PB0)
B000011, // 3. ●●○○○○ (PB0-1)
B000111, // 4. ●●●○○○ (PB0-2)
B001111, // 5. ●●●●○○ (PB0-3)
B011111, // 6. ●●●●●○ (PB0-4)
B111111, // 7. ●●●●●● (Все)
B111110, // 8. ○●●●●● (PB1-5)
B111100, // 9. ○○●●●● (PB2-5)
B111000, // 10. ○○○●●● (PB3-5)
B110000, // 11. ○○○○●● (PB4-5)
B100000 // 12. ○○○○○● (PB5)
};
void btn1ISR() {
unsigned long currentTime = millis();
if (currentTime - lastInterruptTime > debounceDelay) {
if (animationDelay > 50) {
animationDelay -= 30;
}
lastInterruptTime = currentTime;
}
}
void btn2ISR() {
unsigned long currentTime = millis();
if (currentTime - lastInterruptTime > debounceDelay) {
if (animationDelay < 2000) {
animationDelay += 30;
}
lastInterruptTime = currentTime;
}
}
void setup() {
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(btn1Pin, INPUT_PULLUP);
pinMode(btn2Pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(btn1Pin), btn1ISR, FALLING);
attachInterrupt(digitalPinToInterrupt(btn2Pin), btn2ISR, FALLING);
}
void loop() {
for (int i = 0; i < 12; i++) {
byte pattern = patterns[i];
for (int j = 0; j < numLeds; j++) {
if (bitRead(pattern, j)) {
digitalWrite(ledPins[j], HIGH);
} else {
digitalWrite(ledPins[j], LOW);
}
}
delay(animationDelay);
}
}Loading
st-nucleo-c031c6
st-nucleo-c031c6