Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int downButton = PUSH2; // правая кнопка
- const int upButton = PUSH1; // левая кнопка
- const int ledPin = GREEN_LED; // светодиод
- const int redPin = RED_LED;
- const int rulePin = PF_1; // управляющий транзистором pin
- int ticDelay = 500; // размер паузы выключения
- // состояние кнопок
- int buttonState = 0;
- void setup() {
- //
- pinMode(ledPin, OUTPUT);
- pinMode(redPin, OUTPUT);
- pinMode(rulePin, OUTPUT);
- Serial.begin(9600);
- //
- pinMode(downButton, INPUT_PULLUP);
- pinMode(upButton, INPUT_PULLUP);
- }
- void pressButtonIndication(int step){
- Serial.println(ticDelay);
- digitalWrite(redPin, HIGH);
- delay(step);
- digitalWrite(redPin, LOW);
- }
- void delayAndInputPull(int delayMiliseconds){
- int step = 50;
- int pullDelay = 50;
- int buttonState = HIGH;
- int currentDelay = 0;
- while (currentDelay<delayMiliseconds){
- buttonState = digitalRead(upButton);
- if (LOW == buttonState){
- ticDelay+=step;
- pressButtonIndication(step);
- }
- buttonState = digitalRead(downButton);
- if (LOW == buttonState){
- if (ticDelay - step > 0){
- ticDelay-=step;
- }
- pressButtonIndication(200);
- }
- delay(pullDelay);
- currentDelay+=pullDelay;
- }
- }
- void loop(){
- digitalWrite(ledPin, HIGH);
- digitalWrite(rulePin, HIGH);
- delayAndInputPull(ticDelay); // время работы
- digitalWrite(ledPin, LOW);
- digitalWrite(rulePin, LOW);
- delayAndInputPull(ticDelay); // время остывания
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement