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@2:f0215a034e04, 2015-09-28 (annotated)
- Committer:
- yohoo15
- Date:
- Mon Sep 28 14:13:31 2015 +0000
- Revision:
- 2:f0215a034e04
- Parent:
- 1:c855dee2c6d4
Hij doet raar, doet twee dingen door elkaar; ;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| yohoo15 | 0:70a6fd5751a6 | 1 | #include "mbed.h" |
| yohoo15 | 0:70a6fd5751a6 | 2 | #include "QEI.h" |
| yohoo15 | 0:70a6fd5751a6 | 3 | |
| yohoo15 | 0:70a6fd5751a6 | 4 | Serial pc(USBTX, USBRX); |
| yohoo15 | 0:70a6fd5751a6 | 5 | QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in) |
| yohoo15 | 0:70a6fd5751a6 | 6 | |
| yohoo15 | 0:70a6fd5751a6 | 7 | // Define pin for motor control |
| yohoo15 | 0:70a6fd5751a6 | 8 | DigitalOut directionPin(D4); |
| yohoo15 | 0:70a6fd5751a6 | 9 | PwmOut PWM(D5); |
| yohoo15 | 0:70a6fd5751a6 | 10 | |
| yohoo15 | 0:70a6fd5751a6 | 11 | |
| yohoo15 | 0:70a6fd5751a6 | 12 | |
| yohoo15 | 0:70a6fd5751a6 | 13 | // 8400 counts per revolution |
| yohoo15 | 0:70a6fd5751a6 | 14 | // so 8400 / (2 *pi) is counts/pi |
| yohoo15 | 0:70a6fd5751a6 | 15 | |
| yohoo15 | 0:70a6fd5751a6 | 16 | |
| yohoo15 | 0:70a6fd5751a6 | 17 | Ticker tellen; |
| yohoo15 | 2:f0215a034e04 | 18 | |
| yohoo15 | 1:c855dee2c6d4 | 19 | volatile bool stoppen = false; |
| yohoo15 | 0:70a6fd5751a6 | 20 | |
| yohoo15 | 0:70a6fd5751a6 | 21 | void GOTO() |
| yohoo15 | 0:70a6fd5751a6 | 22 | { |
| yohoo15 | 2:f0215a034e04 | 23 | double Offset = 10341 ;//8400 counts is aangegeven op de motor ( is te weinig) 10511 schiet iets over |
| yohoo15 | 1:c855dee2c6d4 | 24 | double resolution = Offset / (2 * 3.14159265); |
| yohoo15 | 0:70a6fd5751a6 | 25 | double Rotation = 4; // rotation in pi |
| yohoo15 | 0:70a6fd5751a6 | 26 | double movement = Rotation * resolution; |
| yohoo15 | 0:70a6fd5751a6 | 27 | |
| yohoo15 | 0:70a6fd5751a6 | 28 | // pc.printf("The number of real rotation is %i \n",Rotation); |
| yohoo15 | 0:70a6fd5751a6 | 29 | |
| yohoo15 | 0:70a6fd5751a6 | 30 | |
| yohoo15 | 0:70a6fd5751a6 | 31 | if (wheel.getPulses() <= movement) { |
| yohoo15 | 0:70a6fd5751a6 | 32 | directionPin.write(1); |
| yohoo15 | 0:70a6fd5751a6 | 33 | PWM.write(0.3); |
| yohoo15 | 0:70a6fd5751a6 | 34 | pc.printf("Pulses is: %i\n", wheel.getPulses()); |
| yohoo15 | 0:70a6fd5751a6 | 35 | } else { |
| yohoo15 | 0:70a6fd5751a6 | 36 | PWM.write(0); |
| yohoo15 | 0:70a6fd5751a6 | 37 | //pc.printf("The motor turned %i rotations \n",Rotation); |
| yohoo15 | 2:f0215a034e04 | 38 | pc.printf("Pulses is: %i\n The motor turned %.2f pi rotations\n", wheel.getPulses(),wheel.getPulses()/resolution); |
| yohoo15 | 0:70a6fd5751a6 | 39 | stoppen = true; |
| yohoo15 | 0:70a6fd5751a6 | 40 | |
| yohoo15 | 0:70a6fd5751a6 | 41 | |
| yohoo15 | 0:70a6fd5751a6 | 42 | } |
| yohoo15 | 0:70a6fd5751a6 | 43 | |
| yohoo15 | 0:70a6fd5751a6 | 44 | |
| yohoo15 | 0:70a6fd5751a6 | 45 | |
| yohoo15 | 0:70a6fd5751a6 | 46 | |
| yohoo15 | 0:70a6fd5751a6 | 47 | } |
| yohoo15 | 0:70a6fd5751a6 | 48 | |
| yohoo15 | 0:70a6fd5751a6 | 49 | |
| yohoo15 | 0:70a6fd5751a6 | 50 | |
| yohoo15 | 0:70a6fd5751a6 | 51 | int main() |
| yohoo15 | 1:c855dee2c6d4 | 52 | |
| yohoo15 | 0:70a6fd5751a6 | 53 | { |
| yohoo15 | 2:f0215a034e04 | 54 | int proberenn = 1000; |
| yohoo15 | 2:f0215a034e04 | 55 | pc.printf("The number of rotation is %i \n",proberenn); |
| yohoo15 | 0:70a6fd5751a6 | 56 | |
| yohoo15 | 2:f0215a034e04 | 57 | while(1){ |
| yohoo15 | 2:f0215a034e04 | 58 | if(stoppen == false){ // doet eerst de while loop en dan begint hij met de ticker |
| yohoo15 | 2:f0215a034e04 | 59 | tellen.attach(&GOTO, 0.1); |
| yohoo15 | 2:f0215a034e04 | 60 | pc.printf("dit is if \n"); |
| yohoo15 | 2:f0215a034e04 | 61 | stoppen = true; |
| yohoo15 | 2:f0215a034e04 | 62 | } else |
| yohoo15 | 2:f0215a034e04 | 63 | { |
| yohoo15 | 2:f0215a034e04 | 64 | |
| yohoo15 | 2:f0215a034e04 | 65 | pc.printf("wees geen bitch \n"); |
| yohoo15 | 2:f0215a034e04 | 66 | |
| yohoo15 | 2:f0215a034e04 | 67 | } |
| yohoo15 | 2:f0215a034e04 | 68 | |
| yohoo15 | 2:f0215a034e04 | 69 | } |
| yohoo15 | 2:f0215a034e04 | 70 | } |
| yohoo15 | 2:f0215a034e04 | 71 | |
| yohoo15 | 2:f0215a034e04 | 72 | |
| yohoo15 | 0:70a6fd5751a6 | 73 | |
| yohoo15 | 0:70a6fd5751a6 | 74 | |
| yohoo15 | 0:70a6fd5751a6 | 75 | |
| yohoo15 | 0:70a6fd5751a6 | 76 | |
| yohoo15 | 0:70a6fd5751a6 | 77 | |
| yohoo15 | 0:70a6fd5751a6 | 78 | |
| yohoo15 | 0:70a6fd5751a6 | 79 | |
| yohoo15 | 0:70a6fd5751a6 | 80 | |
| yohoo15 | 2:f0215a034e04 | 81 |