Opzetje

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Committer:
s1868365
Date:
Fri Oct 04 08:28:04 2019 +0000
Revision:
9:19682cb1d8ee
Parent:
7:2f612f32711a
Statemachine 4/okt om 10.30

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobertoO 0:67c50348f842 1 #include "mbed.h"
boydmartherus 6:3930811edddf 2 #include "MODSERIAL.h"
Mortimerz 7:2f612f32711a 3 #include "FastPWM.h"
Mortimerz 7:2f612f32711a 4 #include "QEI.h"
Mortimerz 3:ea5f67f11825 5
boydmartherus 4:86872b89b21c 6 Serial pc(USBTX,USBRX);
boydmartherus 4:86872b89b21c 7
Mortimerz 7:2f612f32711a 8 // functies aan PINs toevoegen
Mortimerz 7:2f612f32711a 9 FastPWM led(PTA1);
Mortimerz 7:2f612f32711a 10 FastPWM motor(D5);
Mortimerz 3:ea5f67f11825 11
boydmartherus 4:86872b89b21c 12 AnalogIn pot(PTB2);
Mortimerz 7:2f612f32711a 13 InterruptIn button(PTB3);
boydmartherus 4:86872b89b21c 14
Mortimerz 7:2f612f32711a 15 // timer opzetten = ticker
Mortimerz 7:2f612f32711a 16 Ticker ticker_a;
Mortimerz 7:2f612f32711a 17
Mortimerz 7:2f612f32711a 18 // opzetten van hoekbepaling
Mortimerz 7:2f612f32711a 19 int pulses = 4200;
Mortimerz 7:2f612f32711a 20 QEI encoder (D13,D12,NC,pulses);
Mortimerz 3:ea5f67f11825 21
Mortimerz 7:2f612f32711a 22 // aparte functies
Mortimerz 7:2f612f32711a 23 // functie hoekbepaling
Mortimerz 7:2f612f32711a 24 void hoek_bepaling()
Mortimerz 7:2f612f32711a 25 {
Mortimerz 7:2f612f32711a 26 encoder.getPulses();
Mortimerz 7:2f612f32711a 27 }
boydmartherus 6:3930811edddf 28
Mortimerz 7:2f612f32711a 29 //functie motor aansturen met pot
boydmartherus 6:3930811edddf 30 void motor_speed()
boydmartherus 6:3930811edddf 31 {
boydmartherus 6:3930811edddf 32 motor.write(pot);
boydmartherus 6:3930811edddf 33 }
boydmartherus 6:3930811edddf 34
Mortimerz 7:2f612f32711a 35 // functie print output
Mortimerz 7:2f612f32711a 36 void print_output()
boydmartherus 6:3930811edddf 37 {
Mortimerz 7:2f612f32711a 38 pc.printf("pot value is (%f)\r\n",pot.read());
Mortimerz 7:2f612f32711a 39 //pc.printf("pulse is (%i)\r\n",encoder.getPulses());
Mortimerz 7:2f612f32711a 40
Mortimerz 7:2f612f32711a 41 }
Mortimerz 7:2f612f32711a 42
Mortimerz 7:2f612f32711a 43 void main_loop()
Mortimerz 7:2f612f32711a 44 { print_output();
Mortimerz 7:2f612f32711a 45
Mortimerz 7:2f612f32711a 46 //if(button.read() == 0){
Mortimerz 7:2f612f32711a 47 //hoek_bepaling();
Mortimerz 7:2f612f32711a 48 motor_speed();
Mortimerz 7:2f612f32711a 49
Mortimerz 7:2f612f32711a 50 }
Mortimerz 7:2f612f32711a 51
Mortimerz 7:2f612f32711a 52 int main()
Mortimerz 7:2f612f32711a 53 {
Mortimerz 7:2f612f32711a 54 ticker_a.attach(&main_loop, 0.001f);
Mortimerz 7:2f612f32711a 55 while(true){};
Mortimerz 7:2f612f32711a 56 }