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.
main.cpp
- Committer:
- yohoo15
- Date:
- 2015-09-28
- Revision:
- 2:f0215a034e04
- Parent:
- 1:c855dee2c6d4
File content as of revision 2:f0215a034e04:
#include "mbed.h"
#include "QEI.h"
Serial pc(USBTX, USBRX);
QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in)
// Define pin for motor control
DigitalOut directionPin(D4);
PwmOut PWM(D5);
// 8400 counts per revolution
// so 8400 / (2 *pi) is counts/pi
Ticker tellen;
volatile bool stoppen = false;
void GOTO()
{
double Offset = 10341 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over
double resolution = Offset / (2 * 3.14159265);
double Rotation = 4; // rotation in pi
double movement = Rotation * resolution;
// pc.printf("The number of real rotation is %i \n",Rotation);
if (wheel.getPulses() <= movement) {
directionPin.write(1);
PWM.write(0.3);
pc.printf("Pulses is: %i\n", wheel.getPulses());
} else {
PWM.write(0);
//pc.printf("The motor turned %i rotations \n",Rotation);
pc.printf("Pulses is: %i\n The motor turned %.2f pi rotations\n", wheel.getPulses(),wheel.getPulses()/resolution);
stoppen = true;
}
}
int main()
{
int proberenn = 1000;
pc.printf("The number of rotation is %i \n",proberenn);
while(1){
if(stoppen == false){ // doet eerst de while loop en dan begint hij met de ticker
tellen.attach(&GOTO, 0.1);
pc.printf("dit is if \n");
stoppen = true;
} else
{
pc.printf("wees geen bitch \n");
}
}
}