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@0:815f11c4396f, 2010-10-20 (annotated)
- Committer:
- soundhack
- Date:
- Wed Oct 20 21:03:52 2010 +0000
- Revision:
- 0:815f11c4396f
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| soundhack | 0:815f11c4396f | 1 | #include "mbed.h" |
| soundhack | 0:815f11c4396f | 2 | |
| soundhack | 0:815f11c4396f | 3 | // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
| soundhack | 0:815f11c4396f | 4 | |
| soundhack | 0:815f11c4396f | 5 | #define SPEED 0.125 |
| soundhack | 0:815f11c4396f | 6 | |
| soundhack | 0:815f11c4396f | 7 | #define LED_MASK 0x00B40000 |
| soundhack | 0:815f11c4396f | 8 | #define LED1 0x00040000 |
| soundhack | 0:815f11c4396f | 9 | #define LED2 0x00100000 |
| soundhack | 0:815f11c4396f | 10 | #define LED3 0x00200000 |
| soundhack | 0:815f11c4396f | 11 | #define LED4 0x00800000 |
| soundhack | 0:815f11c4396f | 12 | void setled(char); |
| soundhack | 0:815f11c4396f | 13 | |
| soundhack | 0:815f11c4396f | 14 | |
| soundhack | 0:815f11c4396f | 15 | int ledarray[]={LED1,LED2,LED3,LED4}; |
| soundhack | 0:815f11c4396f | 16 | |
| soundhack | 0:815f11c4396f | 17 | PortOut ledport(Port1, LED_MASK); |
| soundhack | 0:815f11c4396f | 18 | |
| soundhack | 0:815f11c4396f | 19 | int main() { |
| soundhack | 0:815f11c4396f | 20 | char a=1; |
| soundhack | 0:815f11c4396f | 21 | |
| soundhack | 0:815f11c4396f | 22 | while(1) |
| soundhack | 0:815f11c4396f | 23 | { |
| soundhack | 0:815f11c4396f | 24 | while (a<8) |
| soundhack | 0:815f11c4396f | 25 | { |
| soundhack | 0:815f11c4396f | 26 | setled(a); |
| soundhack | 0:815f11c4396f | 27 | wait(SPEED); |
| soundhack | 0:815f11c4396f | 28 | setled(0); |
| soundhack | 0:815f11c4396f | 29 | a<<=1; |
| soundhack | 0:815f11c4396f | 30 | } |
| soundhack | 0:815f11c4396f | 31 | while (a>1) |
| soundhack | 0:815f11c4396f | 32 | { |
| soundhack | 0:815f11c4396f | 33 | setled(a); |
| soundhack | 0:815f11c4396f | 34 | wait(SPEED); |
| soundhack | 0:815f11c4396f | 35 | setled(0); |
| soundhack | 0:815f11c4396f | 36 | a>>=1; |
| soundhack | 0:815f11c4396f | 37 | } |
| soundhack | 0:815f11c4396f | 38 | } |
| soundhack | 0:815f11c4396f | 39 | } |
| soundhack | 0:815f11c4396f | 40 | |
| soundhack | 0:815f11c4396f | 41 | void setled(char value) |
| soundhack | 0:815f11c4396f | 42 | { |
| soundhack | 0:815f11c4396f | 43 | int mask=0; |
| soundhack | 0:815f11c4396f | 44 | |
| soundhack | 0:815f11c4396f | 45 | for (int i=0;i<4;i++) |
| soundhack | 0:815f11c4396f | 46 | { |
| soundhack | 0:815f11c4396f | 47 | if (value&1) |
| soundhack | 0:815f11c4396f | 48 | { |
| soundhack | 0:815f11c4396f | 49 | mask|=ledarray[i]; |
| soundhack | 0:815f11c4396f | 50 | } |
| soundhack | 0:815f11c4396f | 51 | value>>=1; |
| soundhack | 0:815f11c4396f | 52 | } |
| soundhack | 0:815f11c4396f | 53 | ledport=mask; |
| soundhack | 0:815f11c4396f | 54 | } |