Six crescent shaped legs

Dependencies:   mbed

main.cpp

Committer:
phairero
Date:
2016-03-24
Revision:
0:0b7259fdb68a
Child:
1:8b0322a353f4

File content as of revision 0:0b7259fdb68a:

#include "mbed.h"
#include "time.h"

Timer timer;
PwmOut mypwm(PB_0);
DigitalOut dir1(PC_0);
DigitalOut dir2(PC_1);
InterruptIn encA(PA_0);
InterruptIn bt(USER_BUTTON);
Serial pc(SERIAL_TX, SERIAL_RX);

int iLoe = 0;
int isItTime = 0;
int iUus = 0;
int iAeg = 0;
//int iVan[2] = {0,0};
double dPwm = 0.01;
int lastB= bt;

void start(){
    iUus = timer.read_us();
    timer.reset();
    }
void stop(){
    iAeg = timer.read_us();
    }

void button(){
    isItTime = 1;
    }

int main(){
    encA.rise(&start);
    encA.fall(&stop);
    bt.fall(&button);
    timer.start();
    mypwm.write(dPwm);
    //mypwm.period_ms(10);
    //mypwm.pulsewidth_ms(4);
    dir1 = 1;
    dir2 = 0;

    while(1) {
        if (isItTime){
            isItTime = 0;
            dPwm = dPwm + 0.1;
            if (dPwm>=1){
                dPwm--;
            }
            mypwm.write(dPwm);
        }
        else {
            pc.printf("%f: %d/%d\n",dPwm,iUus,iAeg);
        }
    }
}