Tests the motor by having the speed follow a sine wave.

Dependencies:   mbed

motor_test.cpp

Committer:
jmar11
Date:
2014-10-06
Revision:
0:113570912de7

File content as of revision 0:113570912de7:

#include "mbed.h"

PwmOut speed = PTE21;       //speed
DigitalOut direct = PTE20;  //direction

int main() {
    float t = 0;
    float val;
          
    while(1){
        val = sin(t)/4;     //motor speed follows a sine wave
        t += 0.00314f;
        
        if(val < 0){        //when val is negative switch direction
            direct = 1;
            speed = val * -1f;
        }
        else{
            direct = 0;
            speed = val;
        }
        
        wait_us(2500);
    }
}