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@1:f75a3567978c, 2018-10-17 (annotated)
- Committer:
- lars123
- Date:
- Wed Oct 17 08:12:59 2018 +0000
- Revision:
- 1:f75a3567978c
- Parent:
- 0:80f93308a3cd
- Child:
- 2:fa2cc8d8e100
formatted code
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 | 1:f75a3567978c | 17 | Motor1PWR.period_us(60); |
lars123 | 1:f75a3567978c | 18 | while(1) { |
lars123 | 1:f75a3567978c | 19 | if(Pot1<0.45f) { |
lars123 | 1:f75a3567978c | 20 | x = Pot1-1; |
lars123 | 1:f75a3567978c | 21 | } else if(Pot1>0.55f) { |
lars123 | 1:f75a3567978c | 22 | x = Pot1; |
lars123 | 1:f75a3567978c | 23 | } else { |
lars123 | 1:f75a3567978c | 24 | x = 0; |
lars123 | 1:f75a3567978c | 25 | } |
lars123 | 1:f75a3567978c | 26 | |
lars123 | 1:f75a3567978c | 27 | if(Pot2<0.45f) { |
lars123 | 1:f75a3567978c | 28 | y = Pot2-1; |
lars123 | 1:f75a3567978c | 29 | } else if(Pot2>0.55f) { |
lars123 | 1:f75a3567978c | 30 | y = Pot2; |
lars123 | 1:f75a3567978c | 31 | } else { |
lars123 | 1:f75a3567978c | 32 | y = 0; |
lars123 | 1:f75a3567978c | 33 | } |
lars123 | 1:f75a3567978c | 34 | pc.printf("x = %f, y = %f\r\n",x,y); |
lars123 | 1:f75a3567978c | 35 | Motor1PWR = fabs(y); |
lars123 | 1:f75a3567978c | 36 | Motor1DIR = y > 0.0f; |
lars123 | 1:f75a3567978c | 37 | Motor2PWR = fabs(x); |
lars123 | 1:f75a3567978c | 38 | Motor2DIR = x > 0.0f; |
lars123 | 1:f75a3567978c | 39 | wait(0.1f); |
lars123 | 0:80f93308a3cd | 40 | } |
lars123 | 1:f75a3567978c | 41 | return(0); |
lars123 | 0:80f93308a3cd | 42 | } |