![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Silahkan dibaca ^_^
Dependencies: Motor mbed millis PID
main.cpp
- Committer:
- gustavaditya
- Date:
- 2016-09-22
- Revision:
- 0:24cb158c4064
- Child:
- 1:8d4fab4e069c
File content as of revision 0:24cb158c4064:
#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; } } }