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: mbed
main.cpp@0:97b4f9625db2, 2016-05-24 (annotated)
- Committer:
- ooseausername
- Date:
- Tue May 24 14:16:46 2016 +0000
- Revision:
- 0:97b4f9625db2
- Child:
- 1:836ed9afcb8a
ENCODER
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ooseausername | 0:97b4f9625db2 | 1 | #include "mbed.h" |
| ooseausername | 0:97b4f9625db2 | 2 | |
| ooseausername | 0:97b4f9625db2 | 3 | PwmOut mypwm(PWM_OUT); |
| ooseausername | 0:97b4f9625db2 | 4 | |
| ooseausername | 0:97b4f9625db2 | 5 | DigitalOut myled(LED1); |
| ooseausername | 0:97b4f9625db2 | 6 | |
| ooseausername | 0:97b4f9625db2 | 7 | int main() { |
| ooseausername | 0:97b4f9625db2 | 8 | |
| ooseausername | 0:97b4f9625db2 | 9 | mypwm.period_ms(10); |
| ooseausername | 0:97b4f9625db2 | 10 | mypwm.pulsewidth_ms(1); |
| ooseausername | 0:97b4f9625db2 | 11 | |
| ooseausername | 0:97b4f9625db2 | 12 | printf("pwm set to %.2f %%\n", mypwm.read() * 100); |
| ooseausername | 0:97b4f9625db2 | 13 | |
| ooseausername | 0:97b4f9625db2 | 14 | while(1) { |
| ooseausername | 0:97b4f9625db2 | 15 | myled = !myled; |
| ooseausername | 0:97b4f9625db2 | 16 | wait(1); |
| ooseausername | 0:97b4f9625db2 | 17 | } |
| ooseausername | 0:97b4f9625db2 | 18 | } |
| ooseausername | 0:97b4f9625db2 | 19 | void _ISR _U2RXInterrupt(void) |
| ooseausername | 0:97b4f9625db2 | 20 | { |
| ooseausername | 0:97b4f9625db2 | 21 | |
| ooseausername | 0:97b4f9625db2 | 22 | static char Temp; |
| ooseausername | 0:97b4f9625db2 | 23 | Temp=U2RXREG; |
| ooseausername | 0:97b4f9625db2 | 24 | if (Receive_Flag==1) |
| ooseausername | 0:97b4f9625db2 | 25 | { |
| ooseausername | 0:97b4f9625db2 | 26 | Receive_Counter++; |
| ooseausername | 0:97b4f9625db2 | 27 | Receive_Data[Receive_Counter]=Temp; |
| ooseausername | 0:97b4f9625db2 | 28 | |
| ooseausername | 0:97b4f9625db2 | 29 | if(Receive_Counter==9) |
| ooseausername | 0:97b4f9625db2 | 30 | { |
| ooseausername | 0:97b4f9625db2 | 31 | Command_Flag=1; |
| ooseausername | 0:97b4f9625db2 | 32 | Receive_Flag=0; |
| ooseausername | 0:97b4f9625db2 | 33 | Receive_Counter=0; |
| ooseausername | 0:97b4f9625db2 | 34 | } |
| ooseausername | 0:97b4f9625db2 | 35 | } |
| ooseausername | 0:97b4f9625db2 | 36 | else |
| ooseausername | 0:97b4f9625db2 | 37 | { |
| ooseausername | 0:97b4f9625db2 | 38 | if(Temp==36) |
| ooseausername | 0:97b4f9625db2 | 39 | { |
| ooseausername | 0:97b4f9625db2 | 40 | Receive_Flag=1; |
| ooseausername | 0:97b4f9625db2 | 41 | Receive_Counter=0; |
| ooseausername | 0:97b4f9625db2 | 42 | Receive_Data[0]= Temp; |
| ooseausername | 0:97b4f9625db2 | 43 | } |
| ooseausername | 0:97b4f9625db2 | 44 | else |
| ooseausername | 0:97b4f9625db2 | 45 | { |
| ooseausername | 0:97b4f9625db2 | 46 | } |
| ooseausername | 0:97b4f9625db2 | 47 | } |
| ooseausername | 0:97b4f9625db2 | 48 | IFS1bits.U2RXIF=0; |
| ooseausername | 0:97b4f9625db2 | 49 | } |
| ooseausername | 0:97b4f9625db2 | 50 | |
| ooseausername | 0:97b4f9625db2 | 51 | |
| ooseausername | 0:97b4f9625db2 | 52 | if(Command_Flag==1) |
| ooseausername | 0:97b4f9625db2 | 53 | { |
| ooseausername | 0:97b4f9625db2 | 54 | Position_Error=(Receive_Data[2]-0x30)*100+(Receive_Data[3]-0x30)*10+(Receive_Data[4]-0x30); |
| ooseausername | 0:97b4f9625db2 | 55 | |
| ooseausername | 0:97b4f9625db2 | 56 | if(Receive_Data[1]=='-') |
| ooseausername | 0:97b4f9625db2 | 57 | Position_Error=-1*Position_Error; |
| ooseausername | 0:97b4f9625db2 | 58 | else Position_Error=Position_Error; |
| ooseausername | 0:97b4f9625db2 | 59 | |
| ooseausername | 0:97b4f9625db2 | 60 | Degree_Error=(Receive_Data[6]-0x30)*100+(Receive_Data[7]-0x30)*10+(Receive_Data[8]-0x30); |
| ooseausername | 0:97b4f9625db2 | 61 | |
| ooseausername | 0:97b4f9625db2 | 62 | if(Receive_Data[5]=='-') |
| ooseausername | 0:97b4f9625db2 | 63 | Degree_Error=-1*Degree_Error; |
| ooseausername | 0:97b4f9625db2 | 64 | else Degree_Error=Degree_Error; |
| ooseausername | 0:97b4f9625db2 | 65 | if(Receive_Data[9]=='j') pwm_duty=148; |
| ooseausername | 0:97b4f9625db2 | 66 | else if (Receive_Data[9]=='k') pwm_duty=100; |
| ooseausername | 0:97b4f9625db2 | 67 | Command_Flag=0; |
| ooseausername | 0:97b4f9625db2 | 68 | } |