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: Encoder HIDScope MODSERIAL mbed
main.cpp
- Committer:
- Vigilance88
- Date:
- 2015-09-20
- Revision:
- 0:4bfe85fb30ab
- Child:
- 1:e0c4625bbbab
File content as of revision 0:4bfe85fb30ab:
#include "mbed.h"
#include "encoder.h"
DigitalOut motor2direction(D6); //D4 en D5 zijn motor 2 (op het motorshield)
PwmOut motor2speed(D7);
DigitalOut motor1direction(D4); //D6 en D7 voor motor 1 (op het motorshield)
PwmOut motor1speed(D5);
InterruptIn stop_knop(D8);
int main()
{
Encoder motor2(D13,D12);
int position = motor2.getPosition();
Serial pc(USBTX,USBRX);
pc.baud(9600);
motor2speed=0.0f;
motor2direction=1;
wait(0.5);
if(stop_knop.read() == 0) {
motor2speed=0.0f;
}
while (true) {
while (position <= 12000) {
motor2direction = 1;
motor2speed = 0.1f;
wait(0.1);
pc.printf("while1: pos: %d, speed %f \r\n",motor2.getPosition(), motor2.getSpeed());
}
while (position >= 70000) {
motor2direction = 0;
motor2speed = 0.1f;
wait(0.1);
pc.printf("while2: pos: %d, speed %f \r\n",motor2.getPosition(), motor2.getSpeed());
}
while (position <= 700 && position >=4) {
motor2speed = 0.1f;
wait(0.1);
}
}
}