Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
2motor-2sensor-hbrug.cpp
- Committer:
- Zweinenstal
- Date:
- 2020-05-29
- Revision:
- 0:2e4509e0eb06
File content as of revision 0:2e4509e0eb06:
#include "mbed.h"
DigitalOut links1(PB_4);
DigitalOut rechts1(PB_5);
DigitalOut links2(PF_0);
DigitalOut rechts2(PF_1);
PwmOut pwm1(PA_8);
PwmOut pwm2(PB_1);
InterruptIn sensor1(PA_10, PullDown);
InterruptIn sensor2(PA_9, PullDown);
Serial pc(USBTX, USBRX);
Timer timer;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
void rechtdoor(){
a = 1;
}
void achteruit(){
b = 1;
}
void linksom(){
c = 1;
}
void rechtsom(){
d = 1;
}
int main(){
int begin;
timer.start();
begin = timer.read_ms();
a = 1;
sensor2.rise(linksom);
sensor1.rise(rechtsom);
while(1) {
if (c == 1 && d == 1){
c = 0;
d = 0;
b = 1;
if(timer.read_ms() - begin>2000){
a = 1;
begin = timer.read_ms();
}
}
else if (c == 1){
links1 = 0;
rechts1 = 0;
links2 = 0;
rechts2 = 1;
if(timer.read_ms() - begin>2000){
c = 0;
a = 1;
begin = timer.read_ms();
}
}
else if (d == 1){
links1 = 1;
rechts1 = 0;
links2 = 0;
rechts2 = 0;
if(timer.read_ms() - begin>2000){
d = 0;
a = 1;
begin = timer.read_ms();
}
}
if (a == 1){
links1 = 1;
rechts1 = 0;
links2 = 0;
rechts2 = 1;
}
if (b == 1){
links1 = 0;
rechts1 = 1;
links2 = 1;
rechts2 = 0;
if(timer.read_ms() - begin>2000){
b = 0;
a = 1;
begin = timer.read_ms();
}
}
pwm1 = 0.5;
pwm2 = 0.5;
}
}

