pawlack

Untitled

Aug 30th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.99 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. const int buttonPin = 7;     // the number of the pushbutton pin
  4.  
  5. int buttonState = 0;         // variable for reading the pushbutton status
  6. int prevButtonState = 0;
  7. int milisek = 0;      // zmienna typu intiger z wartością początkową 0
  8. int sek = 0;     // zmienna typu intiger z wartością początkową 0  
  9. int minut =0;     // zmienna typu intiger z wartością początkową 0
  10. int startTime = millis();
  11. bool IsCounting = false;
  12. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);       //definiujemy zmienną lcd, przez którą będziemy się
  13.         //komunikować z modułem; podajemy do których
  14.         //pinów podłączyliśmy się w Arduino  
  15.  
  16.        
  17. void setup()      // parametry przygotowawcze
  18. {
  19. lcd.begin(16,2);    // parametry wyświetlacza
  20. pinMode(buttonPin, INPUT);       // not really necessary, pins default to INPUT anyway  
  21. pinMode(10, OUTPUT);
  22. }
  23.  
  24.  
  25. bool startLicznika()
  26.   {
  27.    buttonState = digitalRead(buttonPin);  
  28.    
  29.    if (buttonState == 1 && prevButtonState == 0)
  30.    {
  31.    prevButtonState = 1;
  32.    return false;
  33.    }
  34.    
  35.    else if (buttonState == 0 && prevButtonState == 1 && IsCounting == false)
  36.    {
  37.    prevButtonState = 0;
  38.    IsCounting = true;
  39.    milisek = 0;      // zmienna typu intiger z wartością początkową 0
  40.    sek = 0;     // zmienna typu intiger z wartością początkową 0  
  41.    minut =0;     // zmienna typu intiger z wartością początkową 0
  42.    startTime = millis();
  43.    return true;
  44.    
  45.    }
  46.    
  47.    else if (buttonState == 0 && prevButtonState == 1 && IsCounting == true)
  48.    {
  49.    IsCounting = false;
  50.    prevButtonState = 0;
  51.    return false;
  52.    }
  53.  
  54.    else if (buttonState == 0 && prevButtonState == 0 && IsCounting == true)
  55.    {
  56.    return true;
  57.    }
  58.    
  59.    else
  60.    {
  61.    return false;
  62.    }
  63.   }
  64.  
  65. void buzzer()
  66. {
  67.   if (buttonState == 1)
  68.   {
  69.   digitalWrite(10, HIGH);
  70.   }
  71.   else
  72.   {
  73.   digitalWrite(10, LOW);
  74.   }
  75.   }
  76.  
  77. void print() //funkcja updatujaca wyświetlacz
  78.   {
  79.    lcd.setCursor(0,0);    // ustawienie kursora
  80.    lcd.print ("t ");   // wyświetlenie tekstu
  81.    lcd.print (minut);   // wyświetlenie wartości przypisanej do godziny
  82.    lcd.print (":");   // wyświetlenie tekstu -spacja
  83.    lcd.print (sek);   // wyświetlenie wartości przypisanej do dni
  84.    lcd.print (":");   // wyświetlenie tekstu -spacja
  85.    lcd.print (milisek);   // wyświetlenie tekstu -spacja
  86.    buttonState = digitalRead(buttonPin);
  87.    lcd.setCursor(0,1);    // ustawienie kursora
  88.    lcd.print (buttonState);
  89.    lcd.setCursor(3,1);    // ustawienie kursora
  90.    lcd.print (prevButtonState);
  91.    lcd.setCursor(6,1);    // ustawienie kursora
  92.    lcd.print (IsCounting);
  93.  
  94.   }
  95.  
  96.  
  97. void loop()     // główna pętla
  98. {
  99.  
  100.  buzzer();
  101.  print();
  102.  if (startLicznika() == true)
  103.  {
  104.   if (milisek > 999)
  105.     {
  106.     milisek = 0;
  107.     sek ++;
  108.     startTime = millis();
  109.     lcd.clear();
  110.     }
  111.    if (sek > 59)
  112.     {
  113.     sek = 0;
  114.     minut ++;
  115.     }
  116.  milisek = millis() - startTime;
  117.  
  118.  }
  119.  else
  120.  {
  121.  print();
  122.  }
  123.  }
Advertisement
Add Comment
Please, Sign In to add comment