const int ledPin = 11;
const int btnBrightUp = 4;
const int btnBrightDown = 5;
const int btnSpeedUp = 6;
const int btnSpeedDown = 7;
int brightness = 128; // Яркость (0-255)
int blinkDelay = 500; // Задержка мигания в мс
unsigned long lastBlinkTime = 0;
bool ledState = false;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(btnBrightUp, INPUT_PULLUP);
pinMode(btnBrightDown, INPUT_PULLUP);
pinMode(btnSpeedUp, INPUT_PULLUP);
pinMode(btnSpeedDown, INPUT_PULLUP);
}
void loop()
{
if (digitalRead(btnBrightUp) == LOW)
{
brightness = constrain(brightness + 5, 0, 255);
delay(50);
}
if (digitalRead(btnBrightDown) == LOW)
{
brightness = constrain(brightness - 5, 0, 255);
delay(50);
}
if (digitalRead(btnSpeedUp) == LOW)
{
blinkDelay = constrain(blinkDelay - 20, 50, 2000);
delay(50);
}
if (digitalRead(btnSpeedDown) == LOW)
{
blinkDelay = constrain(blinkDelay + 20, 50, 2000);
delay(50);
}
if (millis() - lastBlinkTime >= blinkDelay)
{
lastBlinkTime = millis();
ledState = !ledState;
if (ledState)
{
analogWrite(ledPin, brightness);
}
else
{
analogWrite(ledPin, 0);
}
}
}Cкорость +
Скорость -
яркость +
яркость -