![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Boleh bisa langsung dicoba, tap servo base belum dikalibrasi
main.cpp@1:9284c57e84da, 2019-04-13 (annotated)
- Committer:
- harrymunli
- Date:
- Sat Apr 13 18:51:43 2019 +0000
- Revision:
- 1:9284c57e84da
- Parent:
- 0:9dfae2e18414
- Child:
- 2:34ed8b55eba6
rrrrr
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
harrymunli | 0:9dfae2e18414 | 1 | #include "mbed.h" |
harrymunli | 0:9dfae2e18414 | 2 | #include "Servo.h" |
harrymunli | 0:9dfae2e18414 | 3 | #include "Motor.h" |
harrymunli | 0:9dfae2e18414 | 4 | |
harrymunli | 0:9dfae2e18414 | 5 | /* Nama servo |
harrymunli | 0:9dfae2e18414 | 6 | 4 |
harrymunli | 0:9dfae2e18414 | 7 | 3 |
harrymunli | 0:9dfae2e18414 | 8 | 21 22 |
harrymunli | 0:9dfae2e18414 | 9 | 1 */ |
harrymunli | 0:9dfae2e18414 | 10 | |
harrymunli | 1:9284c57e84da | 11 | Servo servo21(PA_7); |
harrymunli | 1:9284c57e84da | 12 | Servo servo22(PB_6); |
harrymunli | 1:9284c57e84da | 13 | Serial pc(D1, D0); |
harrymunli | 0:9dfae2e18414 | 14 | |
harrymunli | 1:9284c57e84da | 15 | void servo2(float f, float g){ |
harrymunli | 1:9284c57e84da | 16 | servo21.write(f); |
harrymunli | 1:9284c57e84da | 17 | servo22.write(g); |
harrymunli | 1:9284c57e84da | 18 | pc.printf("%f", servo21.read()); |
harrymunli | 1:9284c57e84da | 19 | pc.printf("\n"); |
harrymunli | 1:9284c57e84da | 20 | pc.printf("%f", servo22.read()); |
harrymunli | 1:9284c57e84da | 21 | pc.printf("\n"); |
harrymunli | 0:9dfae2e18414 | 22 | } |
harrymunli | 0:9dfae2e18414 | 23 | |
harrymunli | 0:9dfae2e18414 | 24 | int main() { |
harrymunli | 1:9284c57e84da | 25 | pc.baud(9600); |
harrymunli | 1:9284c57e84da | 26 | pc.printf("test begin\n"); |
harrymunli | 0:9dfae2e18414 | 27 | |
harrymunli | 1:9284c57e84da | 28 | //tes |
harrymunli | 1:9284c57e84da | 29 | servo21.calibrate(0.001,150); |
harrymunli | 1:9284c57e84da | 30 | servo22.calibrate(0.001,150); |
harrymunli | 1:9284c57e84da | 31 | servo21.write(0); |
harrymunli | 1:9284c57e84da | 32 | servo22.write(1.0); |
harrymunli | 1:9284c57e84da | 33 | while(1){ |
harrymunli | 1:9284c57e84da | 34 | float m=0.0; |
harrymunli | 1:9284c57e84da | 35 | float n=0.0; |
harrymunli | 1:9284c57e84da | 36 | pc.scanf("%f",&m); |
harrymunli | 1:9284c57e84da | 37 | pc.printf("test \n"); |
harrymunli | 1:9284c57e84da | 38 | pc.scanf("%f",&n); |
harrymunli | 1:9284c57e84da | 39 | pc.printf("test \n"); |
harrymunli | 1:9284c57e84da | 40 | float f = m; |
harrymunli | 1:9284c57e84da | 41 | float g = n; |
harrymunli | 1:9284c57e84da | 42 | servo2(f,g); |
harrymunli | 1:9284c57e84da | 43 | } |
harrymunli | 0:9dfae2e18414 | 44 | } |