statemachine

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Committer:
boydmartherus
Date:
Mon Sep 23 07:54:49 2019 +0000
Revision:
14:4342436f9f4f
Parent:
12:597f6b8224e5
Child:
15:49f750d895d7
23/9 motor + flip + hoek

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobertoO 0:67c50348f842 1 #include "mbed.h"
Mortimerz 3:ea5f67f11825 2 #include "MODSERIAL.h";
Mortimerz 3:ea5f67f11825 3 #include "FastPWM.h" ;
boydmartherus 9:cdcf30051100 4 #include "QEI.h" ;
boydmartherus 11:5171ac607099 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 10:9101c7a4f219 14
boydmartherus 10:9101c7a4f219 15 int pulses = 131;
boydmartherus 10:9101c7a4f219 16 QEI wheel (D13,D12,NC,pulses);
MarliesWeggemans 4:3e9a8f5d9a1a 17
boydmartherus 12:597f6b8224e5 18 int pin = 1;
boydmartherus 11:5171ac607099 19
boydmartherus 11:5171ac607099 20 void flip()
boydmartherus 11:5171ac607099 21 {
boydmartherus 11:5171ac607099 22 pin=!pin;
boydmartherus 11:5171ac607099 23 }
boydmartherus 11:5171ac607099 24
boydmartherus 11:5171ac607099 25
boydmartherus 10:9101c7a4f219 26 int main()
boydmartherus 10:9101c7a4f219 27 {
boydmartherus 11:5171ac607099 28 printf("Control with dial\n");
boydmartherus 11:5171ac607099 29 button.rise(&flip);
boydmartherus 11:5171ac607099 30 while(true)
boydmartherus 11:5171ac607099 31 {
boydmartherus 11:5171ac607099 32 if (pin == 1)
boydmartherus 11:5171ac607099 33 {
boydmartherus 14:4342436f9f4f 34 printf("now forward");
boydmartherus 10:9101c7a4f219 35 led.write(pot);
boydmartherus 10:9101c7a4f219 36 motor.write(pot);
boydmartherus 12:597f6b8224e5 37 //printf("motor speeed is (%f)\n\r",pot.read());
boydmartherus 12:597f6b8224e5 38 //printf("pulse number is (%i)\n\r",wheel.getPulses());
boydmartherus 11:5171ac607099 39 }
boydmartherus 11:5171ac607099 40 else
boydmartherus 11:5171ac607099 41 {
boydmartherus 14:4342436f9f4f 42 printf("now reversing");
boydmartherus 12:597f6b8224e5 43 led.write(1-pot);
boydmartherus 14:4342436f9f4f 44 motor.write(pot);
boydmartherus 12:597f6b8224e5 45 //printf("motor speeed is (%f)\n\r",pot.read());
boydmartherus 12:597f6b8224e5 46 //printf("pulse number is (%i)\n\r",wheel.getPulses());
boydmartherus 11:5171ac607099 47 }
boydmartherus 11:5171ac607099 48 }
boydmartherus 10:9101c7a4f219 49 }