Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp
- Committer:
- kuni97
- Date:
- 2020-03-09
- Revision:
- 0:55725179457f
File content as of revision 0:55725179457f:
#include "mbed.h" #include "EncoderCounter.h" DigitalOut myled(LED1); DigitalOut enable(PB_15); // initialise PWM PwmOut pwm_motor1(PB_13); PwmOut pwm_motor2(PA_9); PwmOut pwm_motor3(PA_10); // crete Encoder read objects EncoderCounter counter1(PA_6, PC_7); // counter(pin A, pin B) EncoderCounter counter2(PB_6, PB_7); EncoderCounter counter3(PA_0, PA_1); DigitalIn user_button(USER_BUTTON); int main() { // initialise PWM pwm_motor1.period(0.0005f);// 0.5ms 2KHz pwm_motor1.write(0.5f); pwm_motor2.period(0.0005f);// 0.5ms 2KHz pwm_motor2.write(0.5f); pwm_motor3.period(0.0005f);// 0.5ms 2KHz pwm_motor3.write(0.5f); printf("initialization succesfull\n\r"); while (1) { if(!user_button) { // LED off, PWM 60% myled = 0; enable = 1; pwm_motor1.write(0.6f); pwm_motor2.write(0.6f); pwm_motor3.write(0.6f); } else { // LED on, PWM 50% (no motion) enable = 0; myled = 1; pwm_motor1.write(0.5f); pwm_motor2.write(0.5f); pwm_motor3.write(0.5f); } // display encoder values to console printf("counter1 = %d counter2 = %d counter3 = %d\r\n",counter1.read(),counter2.read(),counter3.read()); wait(0.02f); // Takt 0.02s, 50Hz } }