jh
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:70d06581738c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 02 16:44:01 2017 +0000 @@ -0,0 +1,121 @@ +#include "mbed.h" + +Serial bt(USBTX, USBRX); + +AnalogIn linksvoor(A0); +AnalogIn rechtsvoor(A1); +AnalogIn linksachter(A2); +AnalogIn rechtsachter(A3); +AnalogIn afstand(A4); + +DigitalOut steppulse(D9); +DigitalOut enable(D10); +DigitalIn button(D8); +DigitalOut led(D11); + +PwmOut motorlfwd(D2); +PwmOut motorlrwd(D3); +PwmOut motorrfwd(D6); +PwmOut motorrrwd(D7); + +Ticker stepperspeed; +Ticker stepperspeed; + + +int pos; +bool robotrun; +bool object; +int radarspeedsetleft; +int radarspeedsetright; +bool lijnfl; +bool lijnfr; +bool lijnrl; +bool lijnrr; + +void Hbrug(float left, float right) +{ + if (left > 0) { + motorlrwd = 0; + motorlfwd = left; + } else if(left < 0) { + motorlfwd = 0; + motorlrwd = left*-1; + } else { + motorlrwd = 0; + motorlfwd = 0; + } + if (right > 0) { + motorrrwd = 0; + motorrfwd = right; + } else if(right < 0) { + motorrfwd = 0; + motorrrwd = right*-1; + } else { + motorrrwd = 0; + motorrfwd = 0; + } +} +void radar() +{ + float distance; + distance = afstand; + if (distance < 0.2) { + object = 1; + } else { + object = 0; + } +} +void stepper() +{ + if (robotrun == 1) { + steppulse = !steppulse; + pos ++; + if (pos>2080) { + pos = 0; + } + } +} +void lijnsensor() +{ + float a= linksvoor; + float b= rechtsvoor; + float c= linksachter; + float d= rechtsachter; + if (a < 0.5) { + lijnfl = 1; + } else { + lijnfl = 0; + } + if (b < 0.5) { + lijnfl = 1; + } else { + lijnfl = 0; + } + if (c < 0.5) { + lijnfl = 1; + } else { + lijnfl = 0; + } + if (d < 0.5) { + lijnfl = 1; + } else { + lijnfl = 0; + } +} +int main () +{ + enable = 0; + while (1) { +if (robotrun == 1){ + if (lijnfl ==1){ + Hbrug(-1,-0.5); + } + else if (lijnfl ==1){ + Hbrug(-1,-0.5); + } + } + else { + Hbrug(0,0); + } + } +} \ No newline at end of file