Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. const int downButton = PUSH2;     // правая кнопка
  2. const int upButton = PUSH1;     // левая кнопка
  3.  
  4.  
  5. const int ledPin =  GREEN_LED;    // светодиод
  6. const int redPin = RED_LED;
  7.  
  8.  
  9. const int rulePin = PF_1; // управляющий транзистором pin
  10.  
  11.  
  12. int  ticDelay = 500; // размер паузы выключения
  13.  
  14. // состояние кнопок
  15. int buttonState = 0;
  16.  
  17.  
  18.  
  19.  
  20.  
  21. void setup() {
  22.   //
  23.   pinMode(ledPin, OUTPUT);      
  24.   pinMode(redPin, OUTPUT);    
  25.   pinMode(rulePin, OUTPUT);
  26.  
  27.  Serial.begin(9600);
  28.   //
  29.  
  30.  
  31.   pinMode(downButton, INPUT_PULLUP);
  32.   pinMode(upButton, INPUT_PULLUP);  
  33. }
  34.  
  35.  
  36.  
  37. void pressButtonIndication(int step){
  38.     Serial.println(ticDelay);
  39.     digitalWrite(redPin, HIGH);
  40.     delay(step);
  41.     digitalWrite(redPin, LOW);
  42. }
  43.  
  44.  
  45. void delayAndInputPull(int delayMiliseconds){
  46.   int step = 50;
  47.  
  48.   int pullDelay = 50;
  49.  
  50.   int buttonState = HIGH;  
  51.   int currentDelay = 0;
  52.   while (currentDelay<delayMiliseconds){
  53.       buttonState = digitalRead(upButton);
  54.       if (LOW  ==  buttonState){
  55.           ticDelay+=step;
  56.           pressButtonIndication(step);
  57.       }
  58.      
  59.       buttonState = digitalRead(downButton);
  60.       if (LOW  ==  buttonState){
  61.           if (ticDelay - step > 0){
  62.               ticDelay-=step;
  63.           }
  64.           pressButtonIndication(200);
  65.       }
  66.  
  67.       delay(pullDelay);
  68.       currentDelay+=pullDelay;
  69.    
  70.   }
  71. }
  72.  
  73.  
  74.  
  75. void loop(){
  76.  
  77.  
  78.  
  79.   digitalWrite(ledPin, HIGH);
  80.   digitalWrite(rulePin, HIGH);
  81.   delayAndInputPull(ticDelay); // время работы              
  82.  
  83.  
  84.   digitalWrite(ledPin, LOW);    
  85.   digitalWrite(rulePin, LOW);    
  86.   delayAndInputPull(ticDelay); // время остывания
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement