br g5

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Committer:
boydmartherus
Date:
Fri Oct 04 08:23:39 2019 +0000
Revision:
20:184839c241a7
Parent:
19:1a3b61bd88c0
4-okt hele groep in het zelfde bestand

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobertoO 0:67c50348f842 1 #include "mbed.h"
boydmartherus 16:0ff43ed4d259 2 #include "MODSERIAL.h"
boydmartherus 17:3751c2c685ca 3 #include "FastPWM.h"
boydmartherus 17:3751c2c685ca 4 #include "QEI.h"
boydmartherus 7:d5e07647dfea 5
boydmartherus 7:d5e07647dfea 6 Serial pc(USBTX,USBRX);
boydmartherus 7:d5e07647dfea 7
boydmartherus 17:3751c2c685ca 8 // functies aan PINs toevoegen
boydmartherus 9:cdcf30051100 9 FastPWM led(PTA1);
boydmartherus 16:0ff43ed4d259 10 FastPWM motor(D5);
boydmartherus 18:3de4412d8b63 11
boydmartherus 17:3751c2c685ca 12 AnalogIn pot(PTB2);
boydmartherus 20:184839c241a7 13 AnalogIn pot(PTB2);
boydmartherus 17:3751c2c685ca 14 InterruptIn button(PTB3);
boydmartherus 9:cdcf30051100 15
boydmartherus 17:3751c2c685ca 16 // timer opzetten = ticker
boydmartherus 19:1a3b61bd88c0 17 Ticker ticker;
boydmartherus 17:3751c2c685ca 18
boydmartherus 17:3751c2c685ca 19 // opzetten van hoekbepaling
boydmartherus 20:184839c241a7 20 QEI encoder (D13,D12,NC,32,X4_ENCODING);
MarliesWeggemans 4:3e9a8f5d9a1a 21
boydmartherus 17:3751c2c685ca 22 // aparte functies
boydmartherus 17:3751c2c685ca 23 // functie hoekbepaling
boydmartherus 17:3751c2c685ca 24 void hoek_bepaling()
boydmartherus 17:3751c2c685ca 25 {
boydmartherus 18:3de4412d8b63 26 encoder.getPulses();
boydmartherus 17:3751c2c685ca 27 }
boydmartherus 17:3751c2c685ca 28
boydmartherus 17:3751c2c685ca 29 //functie motor aansturen met pot
boydmartherus 17:3751c2c685ca 30 void motor_running()
boydmartherus 17:3751c2c685ca 31 {
boydmartherus 17:3751c2c685ca 32 motor.write(pot);
boydmartherus 17:3751c2c685ca 33 led.write(pot);
boydmartherus 17:3751c2c685ca 34 }
boydmartherus 17:3751c2c685ca 35
boydmartherus 17:3751c2c685ca 36 // functie print output
boydmartherus 18:3de4412d8b63 37 void print_output()
boydmartherus 18:3de4412d8b63 38 {
boydmartherus 19:1a3b61bd88c0 39 pc.printf("motor speed is (%f)\r\n",pot.read());
boydmartherus 18:3de4412d8b63 40 pc.printf("pulse is (%i)\r\n",encoder.getPulses());
boydmartherus 20:184839c241a7 41 }
boydmartherus 20:184839c241a7 42
boydmartherus 20:184839c241a7 43 // functie change direction
boydmartherus 20:184839c241a7 44 void change_direction()
boydmartherus 20:184839c241a7 45 {
boydmartherus 20:184839c241a7 46
boydmartherus 17:3751c2c685ca 47
boydmartherus 17:3751c2c685ca 48 void main_loop()
boydmartherus 17:3751c2c685ca 49 {
boydmartherus 17:3751c2c685ca 50 hoek_bepaling();
boydmartherus 17:3751c2c685ca 51 motor_running();
boydmartherus 19:1a3b61bd88c0 52 }
boydmartherus 19:1a3b61bd88c0 53
boydmartherus 19:1a3b61bd88c0 54 void print_loop()
boydmartherus 19:1a3b61bd88c0 55 {
boydmartherus 18:3de4412d8b63 56 print_output();
boydmartherus 17:3751c2c685ca 57 }
boydmartherus 18:3de4412d8b63 58
boydmartherus 19:1a3b61bd88c0 59 enum (start_wait, move)
boydmartherus 19:1a3b61bd88c0 60
boydmartherus 20:184839c241a7 61 // main functie !!
boydmartherus 20:184839c241a7 62
boydmartherus 10:9101c7a4f219 63 int main()
boydmartherus 10:9101c7a4f219 64 {
boydmartherus 19:1a3b61bd88c0 65 ticker.attach(&main_loop, 0.001f, &print_loop, 1f);
boydmartherus 17:3751c2c685ca 66 while(true){};
boydmartherus 10:9101c7a4f219 67 }