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:6bae2bca8042, 2010-07-14 (annotated)
- Committer:
- gadgetcafe03
- Date:
- Wed Jul 14 10:04:40 2010 +0000
- Revision:
- 0:6bae2bca8042
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| gadgetcafe03 | 0:6bae2bca8042 | 1 | #include "mbed.h" |
| gadgetcafe03 | 0:6bae2bca8042 | 2 | |
| gadgetcafe03 | 0:6bae2bca8042 | 3 | PwmOut led[4] = {PwmOut(LED1), PwmOut(LED2), PwmOut(LED3), PwmOut(LED4), }; |
| gadgetcafe03 | 0:6bae2bca8042 | 4 | |
| gadgetcafe03 | 0:6bae2bca8042 | 5 | int myrand() |
| gadgetcafe03 | 0:6bae2bca8042 | 6 | { |
| gadgetcafe03 | 0:6bae2bca8042 | 7 | static int pr1 = 892327, pr2 = 372, s = 522, mod = 75; |
| gadgetcafe03 | 0:6bae2bca8042 | 8 | |
| gadgetcafe03 | 0:6bae2bca8042 | 9 | s = (pr1 * s + pr2) % mod; |
| gadgetcafe03 | 0:6bae2bca8042 | 10 | |
| gadgetcafe03 | 0:6bae2bca8042 | 11 | return s; |
| gadgetcafe03 | 0:6bae2bca8042 | 12 | } |
| gadgetcafe03 | 0:6bae2bca8042 | 13 | |
| gadgetcafe03 | 0:6bae2bca8042 | 14 | void toAray(int n, int *a) |
| gadgetcafe03 | 0:6bae2bca8042 | 15 | { |
| gadgetcafe03 | 0:6bae2bca8042 | 16 | for (int i=0; i<4; i++) |
| gadgetcafe03 | 0:6bae2bca8042 | 17 | { |
| gadgetcafe03 | 0:6bae2bca8042 | 18 | a[i] = n & 1; |
| gadgetcafe03 | 0:6bae2bca8042 | 19 | n >>= 1; |
| gadgetcafe03 | 0:6bae2bca8042 | 20 | } |
| gadgetcafe03 | 0:6bae2bca8042 | 21 | } |
| gadgetcafe03 | 0:6bae2bca8042 | 22 | |
| gadgetcafe03 | 0:6bae2bca8042 | 23 | int main() { |
| gadgetcafe03 | 0:6bae2bca8042 | 24 | int n[4] = {0, 0, 0, 0,}; |
| gadgetcafe03 | 0:6bae2bca8042 | 25 | int m = 0; |
| gadgetcafe03 | 0:6bae2bca8042 | 26 | |
| gadgetcafe03 | 0:6bae2bca8042 | 27 | while(1) { |
| gadgetcafe03 | 0:6bae2bca8042 | 28 | toAray(myrand(), n); |
| gadgetcafe03 | 0:6bae2bca8042 | 29 | for (int i=0; i<4; i++) |
| gadgetcafe03 | 0:6bae2bca8042 | 30 | { |
| gadgetcafe03 | 0:6bae2bca8042 | 31 | led[i] = n[i]; |
| gadgetcafe03 | 0:6bae2bca8042 | 32 | } |
| gadgetcafe03 | 0:6bae2bca8042 | 33 | m++; |
| gadgetcafe03 | 0:6bae2bca8042 | 34 | wait(1); |
| gadgetcafe03 | 0:6bae2bca8042 | 35 | } |
| gadgetcafe03 | 0:6bae2bca8042 | 36 | } |