Kod za mjerenje i ispis brzine vrtnje.
BrzinaVrtnje.cpp@0:bc2bc6ca43ef, 2020-07-17 (annotated)
- Committer:
- lhorvat
- Date:
- Fri Jul 17 11:31:51 2020 +0000
- Revision:
- 0:bc2bc6ca43ef
Kod za mjerenje i ispis brzine vrtnje.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lhorvat | 0:bc2bc6ca43ef | 1 | #include "BrzinaVrtnje.h" |
lhorvat | 0:bc2bc6ca43ef | 2 | #include "mbed.h" |
lhorvat | 0:bc2bc6ca43ef | 3 | #include "TextLCD.h" |
lhorvat | 0:bc2bc6ca43ef | 4 | Ticker ticker1; |
lhorvat | 0:bc2bc6ca43ef | 5 | Timer timer1; |
lhorvat | 0:bc2bc6ca43ef | 6 | float brzina; |
lhorvat | 0:bc2bc6ca43ef | 7 | TextLCD lcd(p19, p20, p21, p22, p23, p24); |
lhorvat | 0:bc2bc6ca43ef | 8 | BrzinaV::BrzinaV(PinName pin1):int1(pin1) |
lhorvat | 0:bc2bc6ca43ef | 9 | { |
lhorvat | 0:bc2bc6ca43ef | 10 | timer1.start(); |
lhorvat | 0:bc2bc6ca43ef | 11 | void mjerenje(); |
lhorvat | 0:bc2bc6ca43ef | 12 | void ispis(); |
lhorvat | 0:bc2bc6ca43ef | 13 | ticker1.attach(&ispis,1.0); |
lhorvat | 0:bc2bc6ca43ef | 14 | int1.rise(&mjerenje); |
lhorvat | 0:bc2bc6ca43ef | 15 | }; |
lhorvat | 0:bc2bc6ca43ef | 16 | void mjerenje() |
lhorvat | 0:bc2bc6ca43ef | 17 | { |
lhorvat | 0:bc2bc6ca43ef | 18 | brzina = 2055.0/timer1.read_ms(); |
lhorvat | 0:bc2bc6ca43ef | 19 | timer1.reset(); |
lhorvat | 0:bc2bc6ca43ef | 20 | } |
lhorvat | 0:bc2bc6ca43ef | 21 | |
lhorvat | 0:bc2bc6ca43ef | 22 | void ispis() |
lhorvat | 0:bc2bc6ca43ef | 23 | { |
lhorvat | 0:bc2bc6ca43ef | 24 | lcd.cls(); |
lhorvat | 0:bc2bc6ca43ef | 25 | lcd.printf("Brzina: %.2f",brzina); |
lhorvat | 0:bc2bc6ca43ef | 26 | } |