Felix Dransfeld / Mbed 2 deprecated PWM_motor

Dependencies:   MODSERIAL mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MODSERIAL.h"
00003 
00004 AnalogIn pot1(A1);
00005 AnalogIn pot2(A2);
00006 DigitalIn encoder(D7);
00007 PwmOut pwmpin(D5);
00008 DigitalOut directionpin(D4);
00009 DigitalOut directionpin2(D6);
00010 MODSERIAL pc(USBTX, USBRX);
00011 
00012 int main()
00013 {
00014         pc.baud(9600);
00015     
00016     pwmpin.period_us(60); //60 microsecondsPWM period, 16.7 kHz
00017    //float ain1;
00018    //float ain2;
00019     
00020     while(true){
00021        // ain1 = pot1.read();
00022         // ain2 = pot2.read();
00023         
00024         float u = -0.9f; //determineusefulvalue, -0.3f is justanexample
00025         directionpin= u > 0.0f; //eithertrueor false
00026         pwmpin= fabs(u); //pwmduty cycle canonlybepositive, floatingpoint absolute value
00027         
00028         wait(0.5f);
00029         
00030         printf("Motorsnelheid %i \n \r", encoder); 
00031         
00032     }
00033 }