![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
電子ルーレットです
main.cpp@0:c39163aed6b3, 2016-01-23 (annotated)
- Committer:
- kohacraft
- Date:
- Sat Jan 23 03:46:54 2016 +0000
- Revision:
- 0:c39163aed6b3
ver1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kohacraft | 0:c39163aed6b3 | 1 | #include "mbed.h" |
kohacraft | 0:c39163aed6b3 | 2 | #define yukkuri 0.1 //回転が遅くなる具合 |
kohacraft | 0:c39163aed6b3 | 3 | #define startwait 0.01 //最初の回転の速さ |
kohacraft | 0:c39163aed6b3 | 4 | |
kohacraft | 0:c39163aed6b3 | 5 | DigitalOut sp(dp1); |
kohacraft | 0:c39163aed6b3 | 6 | DigitalOut l1(dp6); |
kohacraft | 0:c39163aed6b3 | 7 | DigitalOut l2(dp9); |
kohacraft | 0:c39163aed6b3 | 8 | DigitalOut l3(dp10); |
kohacraft | 0:c39163aed6b3 | 9 | DigitalOut l4(dp11); |
kohacraft | 0:c39163aed6b3 | 10 | DigitalOut l5(dp13); |
kohacraft | 0:c39163aed6b3 | 11 | DigitalOut l6(dp14); |
kohacraft | 0:c39163aed6b3 | 12 | DigitalIn sw(dp15); |
kohacraft | 0:c39163aed6b3 | 13 | |
kohacraft | 0:c39163aed6b3 | 14 | //回転中の音 |
kohacraft | 0:c39163aed6b3 | 15 | void beep() |
kohacraft | 0:c39163aed6b3 | 16 | { |
kohacraft | 0:c39163aed6b3 | 17 | for( int i=0 ; i<50 ; i++ ) |
kohacraft | 0:c39163aed6b3 | 18 | { |
kohacraft | 0:c39163aed6b3 | 19 | sp = 1; |
kohacraft | 0:c39163aed6b3 | 20 | wait(1.0/659.26/4); |
kohacraft | 0:c39163aed6b3 | 21 | sp = 0; |
kohacraft | 0:c39163aed6b3 | 22 | wait(1.0/659.26/4); |
kohacraft | 0:c39163aed6b3 | 23 | } |
kohacraft | 0:c39163aed6b3 | 24 | for( int i=0 ; i<50 ; i++ ) |
kohacraft | 0:c39163aed6b3 | 25 | { |
kohacraft | 0:c39163aed6b3 | 26 | sp = 1; |
kohacraft | 0:c39163aed6b3 | 27 | wait(1.0/783.99/4); |
kohacraft | 0:c39163aed6b3 | 28 | sp = 0; |
kohacraft | 0:c39163aed6b3 | 29 | wait(1.0/783.99/4); |
kohacraft | 0:c39163aed6b3 | 30 | } |
kohacraft | 0:c39163aed6b3 | 31 | } |
kohacraft | 0:c39163aed6b3 | 32 | |
kohacraft | 0:c39163aed6b3 | 33 | int main() { |
kohacraft | 0:c39163aed6b3 | 34 | |
kohacraft | 0:c39163aed6b3 | 35 | //起動音 |
kohacraft | 0:c39163aed6b3 | 36 | beep(); |
kohacraft | 0:c39163aed6b3 | 37 | for( int i=0 ; i<50 ; i++ ) |
kohacraft | 0:c39163aed6b3 | 38 | { |
kohacraft | 0:c39163aed6b3 | 39 | sp = 1; |
kohacraft | 0:c39163aed6b3 | 40 | wait(1.0/659.26/2); |
kohacraft | 0:c39163aed6b3 | 41 | sp = 0; |
kohacraft | 0:c39163aed6b3 | 42 | wait(1.0/659.26/2); |
kohacraft | 0:c39163aed6b3 | 43 | } |
kohacraft | 0:c39163aed6b3 | 44 | for( int i=0 ; i<50 ; i++ ) |
kohacraft | 0:c39163aed6b3 | 45 | { |
kohacraft | 0:c39163aed6b3 | 46 | sp = 1; |
kohacraft | 0:c39163aed6b3 | 47 | wait(1.0/783.99/2); |
kohacraft | 0:c39163aed6b3 | 48 | sp = 0; |
kohacraft | 0:c39163aed6b3 | 49 | wait(1.0/783.99/2); |
kohacraft | 0:c39163aed6b3 | 50 | } |
kohacraft | 0:c39163aed6b3 | 51 | |
kohacraft | 0:c39163aed6b3 | 52 | //LEDを全て光らせる |
kohacraft | 0:c39163aed6b3 | 53 | for( int i=0 ; i<100 ; i++ ) |
kohacraft | 0:c39163aed6b3 | 54 | { |
kohacraft | 0:c39163aed6b3 | 55 | l1 = 1; |
kohacraft | 0:c39163aed6b3 | 56 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 57 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 58 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 59 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 60 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 61 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 62 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 63 | l2 = 1; |
kohacraft | 0:c39163aed6b3 | 64 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 65 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 66 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 67 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 68 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 69 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 70 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 71 | l3 = 1; |
kohacraft | 0:c39163aed6b3 | 72 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 73 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 74 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 75 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 76 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 77 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 78 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 79 | l4 = 1; |
kohacraft | 0:c39163aed6b3 | 80 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 81 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 82 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 83 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 84 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 85 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 86 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 87 | l5 = 1; |
kohacraft | 0:c39163aed6b3 | 88 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 89 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 90 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 91 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 92 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 93 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 94 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 95 | l6 = 1; |
kohacraft | 0:c39163aed6b3 | 96 | wait(0.001); |
kohacraft | 0:c39163aed6b3 | 97 | } |
kohacraft | 0:c39163aed6b3 | 98 | l1 = 1; |
kohacraft | 0:c39163aed6b3 | 99 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 100 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 101 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 102 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 103 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 104 | |
kohacraft | 0:c39163aed6b3 | 105 | float memo; |
kohacraft | 0:c39163aed6b3 | 106 | while(1) |
kohacraft | 0:c39163aed6b3 | 107 | { |
kohacraft | 0:c39163aed6b3 | 108 | //スイッチが押されるまで待つ |
kohacraft | 0:c39163aed6b3 | 109 | while( sw == 0 ) |
kohacraft | 0:c39163aed6b3 | 110 | { |
kohacraft | 0:c39163aed6b3 | 111 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 112 | } |
kohacraft | 0:c39163aed6b3 | 113 | |
kohacraft | 0:c39163aed6b3 | 114 | //LEDが回転する |
kohacraft | 0:c39163aed6b3 | 115 | while(1) { |
kohacraft | 0:c39163aed6b3 | 116 | |
kohacraft | 0:c39163aed6b3 | 117 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 118 | { |
kohacraft | 0:c39163aed6b3 | 119 | memo = startwait; //スイッチが押されていたら最初の回転速度にする |
kohacraft | 0:c39163aed6b3 | 120 | } |
kohacraft | 0:c39163aed6b3 | 121 | l1 = 1; |
kohacraft | 0:c39163aed6b3 | 122 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 123 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 124 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 125 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 126 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 127 | beep(); |
kohacraft | 0:c39163aed6b3 | 128 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 129 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 130 | if( memo > 1.0 ) //速度が1.0以上になったら回転終了 |
kohacraft | 0:c39163aed6b3 | 131 | break; |
kohacraft | 0:c39163aed6b3 | 132 | |
kohacraft | 0:c39163aed6b3 | 133 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 134 | { |
kohacraft | 0:c39163aed6b3 | 135 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 136 | } |
kohacraft | 0:c39163aed6b3 | 137 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 138 | l2 = 1; |
kohacraft | 0:c39163aed6b3 | 139 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 140 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 141 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 142 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 143 | beep(); |
kohacraft | 0:c39163aed6b3 | 144 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 145 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 146 | if( memo > 1.0 ) |
kohacraft | 0:c39163aed6b3 | 147 | break; |
kohacraft | 0:c39163aed6b3 | 148 | |
kohacraft | 0:c39163aed6b3 | 149 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 150 | { |
kohacraft | 0:c39163aed6b3 | 151 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 152 | } |
kohacraft | 0:c39163aed6b3 | 153 | |
kohacraft | 0:c39163aed6b3 | 154 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 155 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 156 | l3 = 1; |
kohacraft | 0:c39163aed6b3 | 157 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 158 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 159 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 160 | beep(); |
kohacraft | 0:c39163aed6b3 | 161 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 162 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 163 | if( memo > 1.0 ) |
kohacraft | 0:c39163aed6b3 | 164 | break; |
kohacraft | 0:c39163aed6b3 | 165 | |
kohacraft | 0:c39163aed6b3 | 166 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 167 | { |
kohacraft | 0:c39163aed6b3 | 168 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 169 | } |
kohacraft | 0:c39163aed6b3 | 170 | |
kohacraft | 0:c39163aed6b3 | 171 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 172 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 173 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 174 | l4 = 1; |
kohacraft | 0:c39163aed6b3 | 175 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 176 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 177 | beep(); |
kohacraft | 0:c39163aed6b3 | 178 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 179 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 180 | if( memo > 1.0 ) |
kohacraft | 0:c39163aed6b3 | 181 | break; |
kohacraft | 0:c39163aed6b3 | 182 | |
kohacraft | 0:c39163aed6b3 | 183 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 184 | { |
kohacraft | 0:c39163aed6b3 | 185 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 186 | } |
kohacraft | 0:c39163aed6b3 | 187 | |
kohacraft | 0:c39163aed6b3 | 188 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 189 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 190 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 191 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 192 | l5 = 1; |
kohacraft | 0:c39163aed6b3 | 193 | l6 = 0; |
kohacraft | 0:c39163aed6b3 | 194 | beep(); |
kohacraft | 0:c39163aed6b3 | 195 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 196 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 197 | if( memo > 1.0 ) |
kohacraft | 0:c39163aed6b3 | 198 | break; |
kohacraft | 0:c39163aed6b3 | 199 | |
kohacraft | 0:c39163aed6b3 | 200 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 201 | { |
kohacraft | 0:c39163aed6b3 | 202 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 203 | } |
kohacraft | 0:c39163aed6b3 | 204 | |
kohacraft | 0:c39163aed6b3 | 205 | l1 = 0; |
kohacraft | 0:c39163aed6b3 | 206 | l2 = 0; |
kohacraft | 0:c39163aed6b3 | 207 | l3 = 0; |
kohacraft | 0:c39163aed6b3 | 208 | l4 = 0; |
kohacraft | 0:c39163aed6b3 | 209 | l5 = 0; |
kohacraft | 0:c39163aed6b3 | 210 | l6 = 1; |
kohacraft | 0:c39163aed6b3 | 211 | beep(); |
kohacraft | 0:c39163aed6b3 | 212 | wait(memo); |
kohacraft | 0:c39163aed6b3 | 213 | memo = memo + yukkuri; |
kohacraft | 0:c39163aed6b3 | 214 | if( memo > 1.0 ) |
kohacraft | 0:c39163aed6b3 | 215 | break; |
kohacraft | 0:c39163aed6b3 | 216 | |
kohacraft | 0:c39163aed6b3 | 217 | if( sw == 1 ) |
kohacraft | 0:c39163aed6b3 | 218 | { |
kohacraft | 0:c39163aed6b3 | 219 | memo = startwait; |
kohacraft | 0:c39163aed6b3 | 220 | } |
kohacraft | 0:c39163aed6b3 | 221 | |
kohacraft | 0:c39163aed6b3 | 222 | |
kohacraft | 0:c39163aed6b3 | 223 | } |
kohacraft | 0:c39163aed6b3 | 224 | |
kohacraft | 0:c39163aed6b3 | 225 | } |
kohacraft | 0:c39163aed6b3 | 226 | } |
kohacraft | 0:c39163aed6b3 | 227 |