![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Silahkan dibaca ^_^
Dependencies: Motor mbed millis PID
Diff: main.cpp
- Revision:
- 0:24cb158c4064
- Child:
- 1:8d4fab4e069c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 22 15:14:41 2016 +0000 @@ -0,0 +1,54 @@ +#include "mbed.h" +#include "millis.h" + +int val; + + int encoder0Pos = 0; + int encoder0PinALast = 0; + int n = 0; + float rpm; + int start = 1; + unsigned long int previousMillis = 0; + + int main(void) { + + DigitalIn encoder0PinA(D3); + DigitalIn encoder0PinB(D4); + Serial pc(USBTX,USBRX); + pc.baud(9600); + startMillis(); + while(1){ + + // AnalogIn(A0); + + + unsigned long int currentMillis = millis(); +// int counter; +// counter=currentMillis/100; + + if (currentMillis-previousMillis==500) + { + previousMillis = currentMillis; + rpm = 120.0/7.0*encoder0Pos; + pc.printf ("Dalam 500 ms = %d ",encoder0Pos); + pc.printf ("rpm = %.0f \n",rpm); + encoder0Pos = 0; + } + + else + { + n = encoder0PinA; + if ((!encoder0PinALast) && (n)) + { + if (!encoder0PinB) + { + encoder0Pos--; + } else { + encoder0Pos++; + } + //pc.printf ("%d \n",encoder0Pos); + } + encoder0PinALast = n; + } + } + } \ No newline at end of file