br g5

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Committer:
boydmartherus
Date:
Mon Sep 23 08:27:53 2019 +0000
Revision:
15:49f750d895d7
Parent:
14:4342436f9f4f
g15 motor + direction!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobertoO 0:67c50348f842 1 #include "mbed.h"
boydmartherus 15:49f750d895d7 2 #include "MODSERIAL.h"
boydmartherus 15:49f750d895d7 3 #include "FastPWM.h"
boydmartherus 15:49f750d895d7 4 #include "QEI.h"
boydmartherus 15:49f750d895d7 5 //#include "Motor.h"
boydmartherus 7:d5e07647dfea 6
boydmartherus 7:d5e07647dfea 7 Serial pc(USBTX,USBRX);
boydmartherus 7:d5e07647dfea 8
Mortimerz 3:ea5f67f11825 9 AnalogIn pot(PTB2);
boydmartherus 11:5171ac607099 10 InterruptIn button(PTB3);
boydmartherus 6:c2608dedfd70 11
boydmartherus 6:c2608dedfd70 12 FastPWM motor(D5);
boydmartherus 9:cdcf30051100 13 FastPWM led(PTA1);
boydmartherus 15:49f750d895d7 14 DigitalOut direction(D4);
boydmartherus 10:9101c7a4f219 15
boydmartherus 10:9101c7a4f219 16 int pulses = 131;
boydmartherus 10:9101c7a4f219 17 QEI wheel (D13,D12,NC,pulses);
MarliesWeggemans 4:3e9a8f5d9a1a 18
boydmartherus 15:49f750d895d7 19 int richting;
boydmartherus 11:5171ac607099 20
boydmartherus 11:5171ac607099 21 void flip()
boydmartherus 11:5171ac607099 22 {
boydmartherus 15:49f750d895d7 23 richting=!richting;
boydmartherus 11:5171ac607099 24 }
boydmartherus 11:5171ac607099 25
boydmartherus 11:5171ac607099 26
boydmartherus 10:9101c7a4f219 27 int main()
boydmartherus 10:9101c7a4f219 28 {
boydmartherus 11:5171ac607099 29 printf("Control with dial\n");
boydmartherus 11:5171ac607099 30 button.rise(&flip);
boydmartherus 11:5171ac607099 31 while(true)
boydmartherus 11:5171ac607099 32 {
boydmartherus 15:49f750d895d7 33 if (richting == 1)
boydmartherus 11:5171ac607099 34 {
boydmartherus 15:49f750d895d7 35 wait(0.05);
boydmartherus 14:4342436f9f4f 36 printf("now forward");
boydmartherus 10:9101c7a4f219 37 led.write(pot);
boydmartherus 10:9101c7a4f219 38 motor.write(pot);
boydmartherus 15:49f750d895d7 39 wait(0.05);
boydmartherus 15:49f750d895d7 40 direction.write(richting);
boydmartherus 12:597f6b8224e5 41 //printf("motor speeed is (%f)\n\r",pot.read());
boydmartherus 12:597f6b8224e5 42 //printf("pulse number is (%i)\n\r",wheel.getPulses());
boydmartherus 11:5171ac607099 43 }
boydmartherus 11:5171ac607099 44 else
boydmartherus 11:5171ac607099 45 {
boydmartherus 15:49f750d895d7 46 wait(0.05);
boydmartherus 14:4342436f9f4f 47 printf("now reversing");
boydmartherus 12:597f6b8224e5 48 led.write(1-pot);
boydmartherus 14:4342436f9f4f 49 motor.write(pot);
boydmartherus 15:49f750d895d7 50 wait(0.05);
boydmartherus 15:49f750d895d7 51 direction.write(richting);
boydmartherus 12:597f6b8224e5 52 //printf("motor speeed is (%f)\n\r",pot.read());
boydmartherus 12:597f6b8224e5 53 //printf("pulse number is (%i)\n\r",wheel.getPulses());
boydmartherus 11:5171ac607099 54 }
boydmartherus 11:5171ac607099 55 }
boydmartherus 10:9101c7a4f219 56 }