Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<arduinoPlatform.h>
- #include<tasks.h>
- #include<interrupts.h>
- #include<stdio.h>
- #include<serial.h>
- #include <pwm.h>
- #include<data.h>
- #include <math.h>
- extern serial Serial;
- #define POTENCIOMETAR A0
- typedef struct{
- int vrednosti[5] = {0, 0, 0, 0, 0};
- } Merenja;
- Merenja g_Potenciometar; //global variable Potenciometar
- int counter_merenja = 0; //vezani je za funkciju ispis_test()
- int skip_after_printed = 0;
- bool just_printed = false;
- void ispis_test(){
- Serial.print("[TEST] [");
- for(int i = 0; i < 4; ++i){
- Serial.print(g_Potenciometar.vrednosti[i]);
- Serial.print(",");
- }
- Serial.print(g_Potenciometar.vrednosti[4]);
- Serial.println("]");
- }
- void load_Potenciometar_vrednost(int id, void* ptrt){
- int potenciometar_vrednost = analogRead(POTENCIOMETAR);
- for(int i = 1; i < 5; ++i){ //idemo do 4 jer cemo na poslednji indeks posle for-a da ubacimo novu vrednost citanja
- g_Potenciometar.vrednosti[i - 1] = g_Potenciometar.vrednosti[i]; //pomeranje clanova niza za jedno mesto u levo
- }
- g_Potenciometar.vrednosti[4] = potenciometar_vrednost;
- if(abs(g_Potenciometar.vrednosti[0] - g_Potenciometar.vrednosti[4]) > 200){
- if(!just_printed){ //pravimo pauzu da ne bi spamovao prilikom ispisa do 5 puta istu liniju za sekundu da ispise (moze maks 2 puta u sekundi da prikaze poruku)
- skip_after_printed = 0;
- Serial.println("U zadnjih 5 ocitavanja je doslo do promene vece od 200.");
- just_printed = true;
- }else if(just_printed){
- if(++skip_after_printed == 5){
- just_printed = false;
- skip_after_printed = 0;
- }
- }
- }
- if(++counter_merenja == 5){
- ispis_test(); //moze se zakomentarisati kad se proveri kod, ovde je samo da se vidi promena u strukturi na svakih 500[ms]
- counter_merenja = 0;
- }
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(POTENCIOMETAR, INPUT);
- createTask(load_Potenciometar_vrednost, 100, TASK_ENABLE, NULL);
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment