MartinSRB

[НРС] Вежбе 13 - Задатак 2

Apr 7th, 2023
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | Source Code | 0 0
  1. #include<arduinoPlatform.h>
  2. #include<tasks.h>
  3. #include<interrupts.h>
  4. #include<stdio.h>
  5. #include<serial.h>
  6. #include <pwm.h>
  7. #include<data.h>
  8.  
  9. extern serial Serial;
  10.  
  11. #define BTN 4
  12.  
  13. int lastState_btn,
  14.     startPressTime,
  15.     click_counter = 0;
  16.  
  17. void print_serial(){
  18.     Serial.print("Broj klikova trenutno: ");
  19.     Serial.println(click_counter);
  20. }
  21.  
  22. void dugme(int id, void* ptrt){
  23.     int  newState = digitalRead(BTN);
  24.     if(lastState_btn < newState){ //uzlazna ivica
  25.         startPressTime = millis();
  26.         lastState_btn = newState;
  27.     }else if(lastState_btn > newState){ //silazna ivica
  28.         if((millis() - startPressTime) >= 2000){
  29.             click_counter++;
  30.             print_serial();
  31.         }
  32.         lastState_btn = newState;
  33.     }
  34. }
  35.  
  36. void setup()
  37. {
  38.     Serial.begin(9600);
  39.     lastState_btn = digitalRead(BTN);
  40.     createTask(dugme, 50, TASK_ENABLE, NULL);
  41. }
  42.  
  43. void loop()
  44. {
  45.  
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment