MartinSRB

[НРС] Вежбе 15 - Задатак 3

May 12th, 2023
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 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 START_LED       26
  12. #define END_LED         33
  13. #define POTENCIJOMETAR  A0
  14.  
  15. #define KORAK           (1024 / 8) //jer ima osam lampica
  16.  
  17. void citanjeSaPotencijometra(int id, void* ptrt){
  18.     int pot_Value = analogRead(POTENCIJOMETAR);
  19.     int max_iteration = pot_Value / KORAK + 25; //dodajemo plus 25 zato sto krecemo od 26 lampice
  20.     for(int i = START_LED; i <= END_LED; ++i){
  21.         if(i <= max_iteration){
  22.             if(!digitalRead(i)){
  23.                 digitalWrite(i, HIGH);
  24.             }
  25.         }else{
  26.             if(digitalRead(i)){
  27.                 digitalWrite(i, LOW);
  28.             }
  29.         }
  30.     }
  31.     Serial.print("Vrednost potencijometra: ");
  32.     Serial.println(pot_Value);
  33. }
  34.  
  35. void setup()
  36. {
  37.     Serial.begin(9600);
  38.     createTask(citanjeSaPotencijometra, 500, TASK_ENABLE, NULL);
  39. }
  40.  
  41. void loop()
  42. {
  43.  
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment