![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
V0.1
Diff: main.cpp
- Revision:
- 0:1045216da12e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Oct 22 11:11:15 2018 +0000 @@ -0,0 +1,42 @@ +#include "mbed.h" + + +//initial allocations +DigitalOut dirpin(D4); +PwmOut pwmpin(D5); +QEI Encoder(D12,D13,NC,64,QEI::X4_ENCODING); + +//volatiles +volatile counts_prev=0; + +//functions +int counts(){ + int counts=Encoder.getPulses(); //MAAK NOG AF MET PREVIOUS COUNTS ONTHOUDEN. + return counts + + +int main(){ + pwmpin.period_us(60); + + //parameters + int caltime=30; //calibration time until condition has been met, caltime=(time/0.1) + float speed=0.50f; + int dir=0 + + //move towards end + for (m=1;2;m++){ + dirpin.write(dir); + pwmpin = speed; + int n=1 + //when motor counts do not change anymore, change direction + while(n<(caltime+1)){ + for (n=1;caltime;n++){ + if (counts()!=counts_prev){ + n=0;} + else {} + wait(0.1);} + dir=dir+1;} + + + + \ No newline at end of file