statemachine
Dependencies: mbed QEI HIDScope biquadFilter MODSERIAL FastPWM
main.cpp@18:3de4412d8b63, 2019-09-23 (annotated)
- Committer:
- boydmartherus
- Date:
- Mon Sep 23 12:53:07 2019 +0000
- Revision:
- 18:3de4412d8b63
- Parent:
- 17:3751c2c685ca
- Child:
- 19:1a3b61bd88c0
ticker + main_loop
Who changed what in which revision?
User | Revision | Line number | New 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 | 17:3751c2c685ca | 13 | InterruptIn button(PTB3); |
boydmartherus | 9:cdcf30051100 | 14 | |
boydmartherus | 17:3751c2c685ca | 15 | // timer opzetten = ticker |
boydmartherus | 18:3de4412d8b63 | 16 | Ticker ticker_a; |
boydmartherus | 17:3751c2c685ca | 17 | |
boydmartherus | 17:3751c2c685ca | 18 | // opzetten van hoekbepaling |
boydmartherus | 16:0ff43ed4d259 | 19 | int pulses = 4200; |
boydmartherus | 18:3de4412d8b63 | 20 | QEI encoder (D13,D12,NC,pulses); |
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 | 18:3de4412d8b63 | 39 | pc.printf("motor speed is (%i)\r\n",pot.read()); |
boydmartherus | 18:3de4412d8b63 | 40 | pc.printf("pulse is (%i)\r\n",encoder.getPulses()); |
boydmartherus | 18:3de4412d8b63 | 41 | } |
boydmartherus | 17:3751c2c685ca | 42 | |
boydmartherus | 17:3751c2c685ca | 43 | void main_loop() |
boydmartherus | 17:3751c2c685ca | 44 | { |
boydmartherus | 17:3751c2c685ca | 45 | hoek_bepaling(); |
boydmartherus | 17:3751c2c685ca | 46 | motor_running(); |
boydmartherus | 18:3de4412d8b63 | 47 | print_output(); |
boydmartherus | 17:3751c2c685ca | 48 | } |
boydmartherus | 18:3de4412d8b63 | 49 | |
boydmartherus | 10:9101c7a4f219 | 50 | int main() |
boydmartherus | 10:9101c7a4f219 | 51 | { |
boydmartherus | 18:3de4412d8b63 | 52 | ticker_a.attach(&main_loop, 0.001f); |
boydmartherus | 17:3751c2c685ca | 53 | while(true){}; |
boydmartherus | 10:9101c7a4f219 | 54 | } |