This code explains the duty cycle changing process by which we can change the speed of the motor

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 DigitalOut vcc(PTC16);
00004 int i;
00005 
00006  
00007 int main()
00008 {
00009 
00010 printf("Press 1 for full duty cycle\r\n",i);
00011 printf("Press 2 for 75% duty cycle\r\n",i);
00012 printf("Press 3 for 50% cycle\r\n",i);
00013 printf("Press 4 for  25% cycle\r\n",i);
00014 scanf("%d\n",&i);
00015 printf("i= %d\n",i);
00016 
00017 while(i==1){vcc=!vcc;}
00018 while(i==2){vcc=!vcc;
00019 wait(0.75);
00020 vcc=0;
00021 wait(0.25);}
00022 
00023 while(i==3){vcc=!vcc;
00024 wait(0.5);
00025 vcc=0;
00026 wait(0.5);}
00027 
00028 while(i==4){vcc=!vcc;
00029 wait(0.25);
00030 vcc=0;
00031 wait(0.75);}
00032 }