![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
BacaMotor
Dependencies: mbed Motornew millis
Diff: main.cpp
- Revision:
- 0:b6f3a4e90aff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 18 15:15:43 2019 +0000 @@ -0,0 +1,71 @@ +//Library +#include "mbed.h" +#include "encoderKRAI.h" +#include "millis.h" +#include "Motor.h" + +//Konstanta +#define PULSE_TO_JARAK 0.61313625 +#define Pressed 0 +#define NotPressed 1 + +encoderKRAI encoderMotorA (PC_11, PC_12, 538, encoderKRAI::X4_ENCODING); +encoderKRAI encoderMotorB (PC_2, PC_3, 538, encoderKRAI::X4_ENCODING); +encoderKRAI encoderMotorC (PC_14, PC_15, 538, encoderKRAI::X4_ENCODING); +encoderKRAI encoderMotorD (PC_10,PC_13, 538, encoderKRAI::X4_ENCODING); + +encoderKRAI encoder1 (PB_7,PB_6, 538, encoderKRAI::X4_ENCODING); +encoderKRAI encoder2 (PB_4,PB_5, 538, encoderKRAI::X4_ENCODING); +encoderKRAI encoder3 (PB_8,PB_9, 538, encoderKRAI::X4_ENCODING); + +/*Motor motorA(PA_7, PA_5, PA_6); +Motor motorB(PB_0, PC_1, PC_0); +Motor motorC(PB_1, PB_15, PB_14); +Motor motorD(PA_11, PA_12, PB_12);*/ +DigitalIn BlueButton(USER_BUTTON); + + +Serial pc(USBTX, USBRX); + +//Variable Global +float timeSampling; +double pulseA; +double pulseB; +double pulseC; +double pulseD; +double pulse1; +double pulse2; +double pulse3; +long lastMillis; + +//Baca Encoder +int main(){ + /* motorA.speed(0.4); + motorB.speed(0.4); + motorC.speed(0.4); + motorD.speed(0.4); + wait(5); + motorA.speed(0.0); + motorB.speed(0.0); + motorC.speed(0.0); + motorD.speed(0.0);*/ + pc.baud(115200); + while(1){ + /*if(BlueButton==Pressed){ + encoderMotorA.reset(); + }*/ + + pulseA = (double)encoderMotorA.getPulses()*PULSE_TO_JARAK; + pulseB = (double)encoderMotorB.getPulses()*PULSE_TO_JARAK; + pulseC = (double)encoderMotorC.getPulses()*PULSE_TO_JARAK; + pulseD = (double)encoderMotorD.getPulses()*PULSE_TO_JARAK; + + //pulse1 = (double)encoder1.getPulses()*PULSE_TO_JARAK; + //pulse2 = (double)encoder2.getPulses()*PULSE_TO_JARAK; + pulse3 = (double)encoder3.getPulses()*PULSE_TO_JARAK; + //pc.printf("A: %lf\t B: %lf\t C: %lf\t D: %lf\t \n", pulseA, pulseB, pulseC, pulseD); + pc.printf("Enc_1: %lf\n", pulse3); + + wait(0.2); + } +} \ No newline at end of file