![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Untuk Kontrol Atas
Dependencies: Motor mRotaryEncoder mbed
Revision 0:bfd2ba3d4b66, committed 2016-09-19
- Comitter:
- danielgoodies
- Date:
- Mon Sep 19 15:38:00 2016 +0000
- Commit message:
- Kontrol Atas Muncrat
Changed in this revision
diff -r 000000000000 -r bfd2ba3d4b66 Motor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Mon Sep 19 15:38:00 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/aberk/code/Motor/#c75b234558af
diff -r 000000000000 -r bfd2ba3d4b66 mRotaryEncoder.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mRotaryEncoder.lib Mon Sep 19 15:38:00 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/charly/code/mRotaryEncoder/#2502b829d452
diff -r 000000000000 -r bfd2ba3d4b66 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 19 15:38:00 2016 +0000 @@ -0,0 +1,59 @@ +#include "mbed.h" +#include "Motor.h" + +/* Pin Declaration */ +Motor Motor1(D6,D7,D8); +DigitalIn encoderpin1(D4); /*Encoder punya 2 buah pin input, 1 Vcc, 1 Ground */ +DigitalIn encoderpin2(D5); + + +/* Variable Declaration */ +int encoder0Pos = 0; +int encoder0PinALast = 0; +int n = 0; +int i = 0; +int boolean = 0; + + /* Main Program */ +int main() { + Serial pc(USBTX,USBRX); + pc.baud(9600); + + pc.printf(" Test Serial Monitor"); + while (1) { + /*if(i>=0 && i<=100 && boolean == 0) { + i++; + if(i==100) { + boolean = 1; + } + } + + if (i<=100 && i>=0 && boolean == 1) { + i--; + if(i==0) { + boolean = 0; + } + } */ + for (i = 100; i >= 0 ; i--) { + Motor1.speed(i*0.01); + wait_ms(20); + } + for (i = 0; i <= 100 ; i++) { + Motor1.speed(i*0.01); + wait_ms(20); + } + //Motor1.speed(0.5); + + n = encoderpin1; + if ((encoder0PinALast == 0) && (n == 1)) { + if ((encoderpin2) == 0) { + encoder0Pos--; + } else { + encoder0Pos++; + } + wait_ms(20); + pc.printf("%d/n", encoder0Pos); + } + encoder0PinALast = n; + } + } \ No newline at end of file
diff -r 000000000000 -r bfd2ba3d4b66 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Sep 19 15:38:00 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/abea610beb85 \ No newline at end of file