Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #include "TimerOne.h"
  2. #include <Wire.h>
  3.  
  4. int SpeedSensor=6; //nr pinu, do ktorego podlaczony czujnik predkosci
  5. unsigned int counter=0; //zlicza sygnaly trafiajace na enkoder
  6. unsigned int counterStan=0; //przechowuje stan licznika po 1s, czestotliwosc sygnalu na pinie 2
  7. float Speed=0;
  8. float diskslots=20;
  9.  
  10. /*
  11. * Funkcje zwiazana z obsluga przerwan
  12. */
  13. void ISR_count(){ //zaliczaj, gdy zmiana stanu na pinie enkoderPin
  14. counter++;
  15. }
  16.  
  17. void ISR_timerone(){
  18. Timer1.detachInterrupt(); //zatrzymanie timera
  19. counterStan=counter;
  20. Speed=(counter/diskslots)*60.00; // predkosc na wyjsciu - obr/min
  21. counter=0;
  22. Timer1.attachInterrupt(ISR_timerone); //wylaczanie timera
  23.  
  24. }
  25.  
  26.  
  27. void setup() {
  28. Serial.begin(9600); //Ustawienie prędkości transmisji
  29. pinMode(SpeedSensor, INPUT);
  30. digitalWrite(SpeedSensor, LOW);
  31.  
  32. Timer1.initialize(100000); //inicjalizacja timera, wykonywane co 1s
  33. attachInterrupt(digitalPinToInterrupt(SpeedSensor), ISR_count, RISING); //wlaczenie przerwania zewnetrznego od zmianu stanu na pinie enkoderPin
  34. //1 arg to nr przerwania, funkcja digitalPinToInterrupt(enkoderPin) zwraca nr przerwania dla danego portu, 2 arg funkcja obslugujaca przerwanie
  35. Timer1.attachInterrupt(ISR_timerone); //gdy wystapi przerwanie to wykonaj funkcje ISR_timerone
  36. }
  37.  
  38. void loop() {
  39. Serial.println("Ilosc impulsow");
  40. Serial.println(counterStan);
  41.  
  42.  
  43. delay(250);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement