Nieuwe versietje

Dependencies:   MODSERIAL mbed

Fork of PWM_motor by Casper Maas

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(D8);
00007 PwmOut pwmpin1(D5);
00008 PwmOut pwmpin2(D6);
00009 DigitalOut directionpin(D4);
00010 DigitalOut directionpin2(D7);
00011 MODSERIAL pc(USBTX, USBRX);
00012 
00013 int main()
00014 {
00015         pc.baud(9600);
00016     
00017     pwmpin1.period_us(60); //60 microsecondsPWM period, 16.7 kHz
00018     pwmpin2.period_us(60);
00019    float ain1;
00020    //float ain2;
00021     
00022     while(true){
00023        ain1 = pot1.read();
00024         // ain2 = pot2.read();
00025         
00026         
00027         
00028         float u = ain1; //determineusefulvalue, -0.3f is justanexample
00029         directionpin= u > 0.0f; //eithertrueor false
00030         pwmpin1= fabs(u); //pwmduty cycle canonlybepositive, floatingpoint absolute value
00031         pwmpin2= fabs(u);
00032         
00033         wait(0.5f);
00034         
00035         printf("Motorsnelheid %i \n \r", encoder); 
00036         
00037     }
00038 }