masamitsu shibata
/
test5
homework
main.cpp@2:46e449180029, 2014-05-01 (annotated)
- Committer:
- 12f2025e
- Date:
- Thu May 01 03:59:15 2014 +0000
- Revision:
- 2:46e449180029
- Parent:
- 1:3917701817b4
homework
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojiro | 0:5193eafa81b6 | 1 | #include "mbed.h" |
Kojiro | 0:5193eafa81b6 | 2 | |
Kojiro | 0:5193eafa81b6 | 3 | BusOut leds(P1_13, P1_14, P1_22, P0_17, P0_18, P0_19, P1_15, P0_1); |
Kojiro | 0:5193eafa81b6 | 4 | |
12f2025e | 2:46e449180029 | 5 | void rotate1(); |
12f2025e | 2:46e449180029 | 6 | void rotate2(); |
12f2025e | 2:46e449180029 | 7 | void rotate3(); |
12f2025e | 2:46e449180029 | 8 | void all1(); |
Kojiro | 1:3917701817b4 | 9 | void sitei(); |
12f2025e | 2:46e449180029 | 10 | void all2(); |
Kojiro | 0:5193eafa81b6 | 11 | |
Kojiro | 0:5193eafa81b6 | 12 | int main() |
Kojiro | 0:5193eafa81b6 | 13 | { |
Kojiro | 0:5193eafa81b6 | 14 | |
Kojiro | 0:5193eafa81b6 | 15 | while(1) |
Kojiro | 0:5193eafa81b6 | 16 | { |
12f2025e | 2:46e449180029 | 17 | rotate1(); |
12f2025e | 2:46e449180029 | 18 | rotate2(); |
12f2025e | 2:46e449180029 | 19 | rotate3(); |
12f2025e | 2:46e449180029 | 20 | wait(0.2); |
12f2025e | 2:46e449180029 | 21 | all1(); |
Kojiro | 1:3917701817b4 | 22 | sitei(); |
12f2025e | 2:46e449180029 | 23 | all2(); |
12f2025e | 2:46e449180029 | 24 | all2(); |
12f2025e | 2:46e449180029 | 25 | all2(); |
12f2025e | 2:46e449180029 | 26 | all2(); |
12f2025e | 2:46e449180029 | 27 | } |
12f2025e | 2:46e449180029 | 28 | } |
12f2025e | 2:46e449180029 | 29 | |
12f2025e | 2:46e449180029 | 30 | void rotate1() |
12f2025e | 2:46e449180029 | 31 | { |
12f2025e | 2:46e449180029 | 32 | volatile uint8_t i ; |
12f2025e | 2:46e449180029 | 33 | for(i = 0; i < 8; i++) |
12f2025e | 2:46e449180029 | 34 | { |
12f2025e | 2:46e449180029 | 35 | leds = 1 << i; |
12f2025e | 2:46e449180029 | 36 | wait(0.3); |
Kojiro | 0:5193eafa81b6 | 37 | } |
Kojiro | 0:5193eafa81b6 | 38 | } |
Kojiro | 1:3917701817b4 | 39 | |
12f2025e | 2:46e449180029 | 40 | void rotate2() |
Kojiro | 1:3917701817b4 | 41 | { |
12f2025e | 2:46e449180029 | 42 | volatile uint8_t j ; |
12f2025e | 2:46e449180029 | 43 | for(j = 0; j < 7; j=j+2) |
12f2025e | 2:46e449180029 | 44 | { |
12f2025e | 2:46e449180029 | 45 | leds = 192 >> j; |
12f2025e | 2:46e449180029 | 46 | wait(0.3); |
12f2025e | 2:46e449180029 | 47 | } |
12f2025e | 2:46e449180029 | 48 | } |
12f2025e | 2:46e449180029 | 49 | |
12f2025e | 2:46e449180029 | 50 | void rotate3() |
Kojiro | 0:5193eafa81b6 | 51 | { |
12f2025e | 2:46e449180029 | 52 | volatile uint8_t k ; |
12f2025e | 2:46e449180029 | 53 | for(k = 0; k < 5; k=k+4) |
Kojiro | 0:5193eafa81b6 | 54 | { |
12f2025e | 2:46e449180029 | 55 | leds = 15 << k; |
12f2025e | 2:46e449180029 | 56 | wait(0.3); |
Kojiro | 0:5193eafa81b6 | 57 | } |
12f2025e | 2:46e449180029 | 58 | } |
Kojiro | 1:3917701817b4 | 59 | |
12f2025e | 2:46e449180029 | 60 | void all1() |
12f2025e | 2:46e449180029 | 61 | { |
12f2025e | 2:46e449180029 | 62 | leds=0xff; |
12f2025e | 2:46e449180029 | 63 | wait(0.5); |
12f2025e | 2:46e449180029 | 64 | leds=0x00; |
12f2025e | 2:46e449180029 | 65 | wait(0.3); |
Kojiro | 1:3917701817b4 | 66 | } |
Kojiro | 1:3917701817b4 | 67 | |
Kojiro | 1:3917701817b4 | 68 | void sitei() |
Kojiro | 1:3917701817b4 | 69 | { |
12f2025e | 2:46e449180029 | 70 | leds=0x01; |
12f2025e | 2:46e449180029 | 71 | wait(0.3); |
12f2025e | 2:46e449180029 | 72 | leds=0x80; |
12f2025e | 2:46e449180029 | 73 | wait(0.3); |
12f2025e | 2:46e449180029 | 74 | leds=0x02; |
12f2025e | 2:46e449180029 | 75 | wait(0.3); |
12f2025e | 2:46e449180029 | 76 | leds=0x40; |
12f2025e | 2:46e449180029 | 77 | wait(0.3); |
12f2025e | 2:46e449180029 | 78 | leds=0x04; |
12f2025e | 2:46e449180029 | 79 | wait(0.3); |
12f2025e | 2:46e449180029 | 80 | leds=0x20; |
12f2025e | 2:46e449180029 | 81 | wait(0.3); |
12f2025e | 2:46e449180029 | 82 | leds=0x08; |
12f2025e | 2:46e449180029 | 83 | wait(0.3); |
12f2025e | 2:46e449180029 | 84 | leds=0x10; |
12f2025e | 2:46e449180029 | 85 | wait(0.3); |
12f2025e | 2:46e449180029 | 86 | leds=0x18; |
12f2025e | 2:46e449180029 | 87 | wait(0.3); |
12f2025e | 2:46e449180029 | 88 | leds=0x3c; |
12f2025e | 2:46e449180029 | 89 | wait(0.3); |
12f2025e | 2:46e449180029 | 90 | leds=0x7e; |
12f2025e | 2:46e449180029 | 91 | wait(0.3); |
12f2025e | 2:46e449180029 | 92 | } |
Kojiro | 1:3917701817b4 | 93 | |
12f2025e | 2:46e449180029 | 94 | void all2() |
12f2025e | 2:46e449180029 | 95 | { |
12f2025e | 2:46e449180029 | 96 | leds=0xff; |
12f2025e | 2:46e449180029 | 97 | wait(0.125); |
12f2025e | 2:46e449180029 | 98 | leds=0x00; |
12f2025e | 2:46e449180029 | 99 | wait(0.125); |
12f2025e | 2:46e449180029 | 100 | } |