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: Encoder MODSERIAL mbed
main.cpp
00001 #include "mbed.h" 00002 #include "encoder.h" 00003 #include "MODSERIAL.h" 00004 00005 DigitalOut led(LED_RED); 00006 DigitalOut direction1(D7); 00007 PwmOut speed1(D6); 00008 DigitalIn button(PTC6); 00009 00010 Encoder motor1(D13,D12,true);// call the encoder 00011 MODSERIAL pc(USBTX,USBRX); 00012 00013 int main() 00014 { 00015 pc.baud(115200); 00016 float maximum=1.0; 00017 direction1.write(false);//turn motor CCW or CW if set to 0 00018 //motor CW = 0 00019 //motor CCW = 1 00020 while(1){//while on, turn on motor 00021 speed1.period_us(100);//Set period of PWM to 100 us. 00022 for(float cycle=0.5; cycle < maximum; cycle=cycle + 0.1){ 00023 speed1.write(cycle);//write the new speed to the motor 00024 wait(1.0);// wait 1 second to switch to higher speed 00025 } //it only turns at the last 5 speeds, so about 0.6 till 1.0 00026 }// the cause of this is the friction it has to work against during rotation 00027 } 00028
Generated on Thu Jul 21 2022 16:30:57 by
1.7.2