![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Code for the first milestone of Project Biorobotics. Make 2 motors turn with a speed indicated by the Pod-meters
Dependencies: FastPWM HIDScope MODSERIAL mbed
main.cpp@0:50c494034326, 2018-09-24 (annotated)
- Committer:
- Mirjam
- Date:
- Mon Sep 24 14:48:19 2018 +0000
- Revision:
- 0:50c494034326
- Child:
- 1:d6acc3c6261a
Declaration of in and outputs. Bug on set of pwm
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mirjam | 0:50c494034326 | 1 | #include "mbed.h" |
Mirjam | 0:50c494034326 | 2 | #include "FastPWM.h" |
Mirjam | 0:50c494034326 | 3 | #include "MODSERIAL.h" |
Mirjam | 0:50c494034326 | 4 | #include "HIDScope.h" |
Mirjam | 0:50c494034326 | 5 | |
Mirjam | 0:50c494034326 | 6 | |
Mirjam | 0:50c494034326 | 7 | AnalogIn potmeter1(PTC10); |
Mirjam | 0:50c494034326 | 8 | AnalogIn potmeter2(PTC11); |
Mirjam | 0:50c494034326 | 9 | MODSERIAL pc(USBTX, USBRX); |
Mirjam | 0:50c494034326 | 10 | //D4 is a digital input for the microcontroller, so should be an digitalOut |
Mirjam | 0:50c494034326 | 11 | //from the K64F. It will tell the motor shiel to let Motor1 turn clockwise |
Mirjam | 0:50c494034326 | 12 | //of count clockwise (CW of CCW). D4 for motor 2 |
Mirjam | 0:50c494034326 | 13 | DigitalOut directionM1(D4); |
Mirjam | 0:50c494034326 | 14 | DigitalOut directionM2(D7); |
Mirjam | 0:50c494034326 | 15 | //D5 is a PWM input for the motor controller and determines the PWM signal |
Mirjam | 0:50c494034326 | 16 | //that the motor controller gives to Motor 1. Higher PWM, higer average voltage. |
Mirjam | 0:50c494034326 | 17 | // D6 for motor 2 |
Mirjam | 0:50c494034326 | 18 | FastPWM motor1_pwm(D5); |
Mirjam | 0:50c494034326 | 19 | FastPWM motor2_pwm(D6); |
Mirjam | 0:50c494034326 | 20 | |
Mirjam | 0:50c494034326 | 21 | int frequency_pwm = 1000; // 1 kHz PWM |
Mirjam | 0:50c494034326 | 22 | motor1_pwm.period(1.0f/frequency_pwm); //T=1/f |
Mirjam | 0:50c494034326 | 23 | |
Mirjam | 0:50c494034326 | 24 | int main(void) |
Mirjam | 0:50c494034326 | 25 | { |
Mirjam | 0:50c494034326 | 26 | |
Mirjam | 0:50c494034326 | 27 | |
Mirjam | 0:50c494034326 | 28 | |
Mirjam | 0:50c494034326 | 29 | while(true){ |
Mirjam | 0:50c494034326 | 30 | |
Mirjam | 0:50c494034326 | 31 | } |
Mirjam | 0:50c494034326 | 32 | |
Mirjam | 0:50c494034326 | 33 | } |