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: MODSERIAL mbed HIDScope
main.cpp@0:80f93308a3cd, 2018-10-15 (annotated)
- Committer:
- lars123
- Date:
- Mon Oct 15 13:17:29 2018 +0000
- Revision:
- 0:80f93308a3cd
- Child:
- 1:f75a3567978c
Versie kan twee motors aansturen met Potmeters;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lars123 | 0:80f93308a3cd | 1 | #include "mbed.h" |
lars123 | 0:80f93308a3cd | 2 | #include "MODSERIAL.h" |
lars123 | 0:80f93308a3cd | 3 | |
lars123 | 0:80f93308a3cd | 4 | |
lars123 | 0:80f93308a3cd | 5 | PwmOut Motor2PWR(D5); |
lars123 | 0:80f93308a3cd | 6 | DigitalOut Motor2DIR(D4); |
lars123 | 0:80f93308a3cd | 7 | PwmOut Motor1PWR(D6); |
lars123 | 0:80f93308a3cd | 8 | DigitalOut Motor1DIR(D7); |
lars123 | 0:80f93308a3cd | 9 | AnalogIn Pot1(PTB2); |
lars123 | 0:80f93308a3cd | 10 | AnalogIn Pot2(PTB3); |
lars123 | 0:80f93308a3cd | 11 | MODSERIAL pc(USBTX, USBRX); |
lars123 | 0:80f93308a3cd | 12 | |
lars123 | 0:80f93308a3cd | 13 | float x = 0; |
lars123 | 0:80f93308a3cd | 14 | float y = 0; |
lars123 | 0:80f93308a3cd | 15 | int main() |
lars123 | 0:80f93308a3cd | 16 | { |
lars123 | 0:80f93308a3cd | 17 | Motor1PWR.period_us(60); |
lars123 | 0:80f93308a3cd | 18 | while(1){ |
lars123 | 0:80f93308a3cd | 19 | if(Pot1<0.45f) |
lars123 | 0:80f93308a3cd | 20 | { |
lars123 | 0:80f93308a3cd | 21 | x = Pot1-1; |
lars123 | 0:80f93308a3cd | 22 | } |
lars123 | 0:80f93308a3cd | 23 | else if(Pot1>0.55f) |
lars123 | 0:80f93308a3cd | 24 | { |
lars123 | 0:80f93308a3cd | 25 | x = Pot1; |
lars123 | 0:80f93308a3cd | 26 | } |
lars123 | 0:80f93308a3cd | 27 | else |
lars123 | 0:80f93308a3cd | 28 | { |
lars123 | 0:80f93308a3cd | 29 | x = 0; |
lars123 | 0:80f93308a3cd | 30 | } |
lars123 | 0:80f93308a3cd | 31 | |
lars123 | 0:80f93308a3cd | 32 | if(Pot2<0.45f) |
lars123 | 0:80f93308a3cd | 33 | { |
lars123 | 0:80f93308a3cd | 34 | y = Pot2-1; |
lars123 | 0:80f93308a3cd | 35 | } |
lars123 | 0:80f93308a3cd | 36 | else if(Pot2>0.55f) |
lars123 | 0:80f93308a3cd | 37 | { |
lars123 | 0:80f93308a3cd | 38 | y = Pot2; |
lars123 | 0:80f93308a3cd | 39 | } |
lars123 | 0:80f93308a3cd | 40 | else |
lars123 | 0:80f93308a3cd | 41 | { |
lars123 | 0:80f93308a3cd | 42 | y = 0; |
lars123 | 0:80f93308a3cd | 43 | } |
lars123 | 0:80f93308a3cd | 44 | pc.printf("x = %f, y = %f\r\n",x,y); |
lars123 | 0:80f93308a3cd | 45 | Motor1PWR = fabs(y); |
lars123 | 0:80f93308a3cd | 46 | Motor1DIR = y > 0.0f; |
lars123 | 0:80f93308a3cd | 47 | Motor2PWR = fabs(x); |
lars123 | 0:80f93308a3cd | 48 | Motor2DIR = x > 0.0f; |
lars123 | 0:80f93308a3cd | 49 | wait(0.1f); |
lars123 | 0:80f93308a3cd | 50 | } |
lars123 | 0:80f93308a3cd | 51 | return(0); |
lars123 | 0:80f93308a3cd | 52 | } |