met comments 710

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM demomode

Committer:
Mortimerz
Date:
Fri Oct 04 08:41:04 2019 +0000
Revision:
19:dd9a61699449
Parent:
18:3de4412d8b63
Child:
22:8340aa6676d7
werkende motor;

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
Mortimerz 19:dd9a61699449 9 DigitalOut led1(D2);
boydmartherus 9:cdcf30051100 10 FastPWM led(PTA1);
Mortimerz 19:dd9a61699449 11 FastPWM motor(D6);
Mortimerz 19:dd9a61699449 12 DigitalOut motor_dir(D7);
boydmartherus 17:3751c2c685ca 13 AnalogIn pot(PTB2);
boydmartherus 17:3751c2c685ca 14 InterruptIn button(PTB3);
boydmartherus 9:cdcf30051100 15
boydmartherus 17:3751c2c685ca 16 // timer opzetten = ticker
Mortimerz 19:dd9a61699449 17 Ticker ticker;
boydmartherus 17:3751c2c685ca 18
boydmartherus 17:3751c2c685ca 19 // opzetten van hoekbepaling
Mortimerz 19:dd9a61699449 20 QEI encoder(D13,D12,NC,32,QEI::X4_ENCODING);
Mortimerz 19:dd9a61699449 21 QEI encoder_2(D11,D10,NC,32,QEI::X4_ENCODING);
MarliesWeggemans 4:3e9a8f5d9a1a 22
boydmartherus 17:3751c2c685ca 23 // aparte functies
boydmartherus 17:3751c2c685ca 24 // functie hoekbepaling
boydmartherus 17:3751c2c685ca 25 void hoek_bepaling()
boydmartherus 17:3751c2c685ca 26 {
boydmartherus 18:3de4412d8b63 27 encoder.getPulses();
Mortimerz 19:dd9a61699449 28 led1 = !led1;
Mortimerz 19:dd9a61699449 29 wait_ms(0.1f);
boydmartherus 17:3751c2c685ca 30 }
boydmartherus 17:3751c2c685ca 31
boydmartherus 17:3751c2c685ca 32 //functie motor aansturen met pot
Mortimerz 19:dd9a61699449 33 void motor_speed()
boydmartherus 17:3751c2c685ca 34 {
boydmartherus 17:3751c2c685ca 35 motor.write(pot);
boydmartherus 17:3751c2c685ca 36 }
boydmartherus 17:3751c2c685ca 37
boydmartherus 17:3751c2c685ca 38 // functie print output
boydmartherus 18:3de4412d8b63 39 void print_output()
Mortimerz 19:dd9a61699449 40 {
boydmartherus 18:3de4412d8b63 41 }
boydmartherus 17:3751c2c685ca 42
boydmartherus 17:3751c2c685ca 43 void main_loop()
Mortimerz 19:dd9a61699449 44 {
Mortimerz 19:dd9a61699449 45 //print_output();
Mortimerz 19:dd9a61699449 46 //if(button.read() == 0){
Mortimerz 19:dd9a61699449 47 //hoek_bepaling();
Mortimerz 19:dd9a61699449 48 motor_speed();
Mortimerz 19:dd9a61699449 49
boydmartherus 17:3751c2c685ca 50 }
boydmartherus 18:3de4412d8b63 51
boydmartherus 10:9101c7a4f219 52 int main()
boydmartherus 10:9101c7a4f219 53 {
Mortimerz 19:dd9a61699449 54 ticker.attach(&main_loop, 0.1f);
Mortimerz 19:dd9a61699449 55 while(true){
Mortimerz 19:dd9a61699449 56 pc.printf("pot value is (%f),pulse is (%d),pulse 2 (%d)\r\n",pot.read(),encoder.getPulses(),encoder_2.getPulses());
Mortimerz 19:dd9a61699449 57 wait(0.1f);
Mortimerz 19:dd9a61699449 58 };
boydmartherus 10:9101c7a4f219 59 }