| 217 | |
| 218 | |
| 219 | = 程式三 = |
| 220 | {{{ |
| 221 | /* |
| 222 | Blink |
| 223 | Turns on an LED on for one second, then off for one second, repeatedly. |
| 224 | |
| 225 | This example code is in the public domain. |
| 226 | */ |
| 227 | |
| 228 | void setup() { |
| 229 | // initialize the digital pin as an output. |
| 230 | // Pin 13 has an LED connected on most Arduino boards: |
| 231 | pinMode(2, OUTPUT); |
| 232 | pinMode(3, OUTPUT); |
| 233 | pinMode(4, OUTPUT); |
| 234 | pinMode(5, OUTPUT); |
| 235 | pinMode(6, OUTPUT); |
| 236 | pinMode(7, OUTPUT); |
| 237 | pinMode(8, OUTPUT); |
| 238 | pinMode(9, OUTPUT); |
| 239 | digitalWrite(2, LOW); |
| 240 | digitalWrite(3, LOW); |
| 241 | digitalWrite(4, LOW); |
| 242 | digitalWrite(5, LOW); |
| 243 | digitalWrite(6, LOW); |
| 244 | digitalWrite(7, LOW); |
| 245 | digitalWrite(8, LOW); |
| 246 | digitalWrite(9, LOW); |
| 247 | |
| 248 | pinMode(10, OUTPUT); |
| 249 | pinMode(11, OUTPUT); |
| 250 | pinMode(12, OUTPUT); |
| 251 | pinMode(13, OUTPUT); |
| 252 | pinMode(14, OUTPUT); |
| 253 | pinMode(15, OUTPUT); |
| 254 | pinMode(16, OUTPUT); |
| 255 | pinMode(17, OUTPUT); |
| 256 | digitalWrite(10, HIGH); |
| 257 | digitalWrite(11, HIGH); |
| 258 | digitalWrite(12, HIGH); |
| 259 | digitalWrite(13, HIGH); |
| 260 | digitalWrite(14, HIGH); |
| 261 | digitalWrite(15, HIGH); |
| 262 | digitalWrite(16, HIGH); |
| 263 | digitalWrite(17, HIGH); |
| 264 | } |
| 265 | |
| 266 | void loop() { |
| 267 | |
| 268 | // time 1 |
| 269 | digitalWrite(2, HIGH); // HIGH |
| 270 | // digitalWrite(3, HIGH); // HIGH |
| 271 | // digitalWrite(4, HIGH); // HIGH |
| 272 | // digitalWrite(5, HIGH); // HIGH |
| 273 | // digitalWrite(6, HIGH); // HIGH |
| 274 | // digitalWrite(7, HIGH); // HIGH |
| 275 | // digitalWrite(8, HIGH); // HIGH |
| 276 | digitalWrite(10, LOW); |
| 277 | digitalWrite(11, LOW); |
| 278 | digitalWrite(12, LOW); |
| 279 | digitalWrite(13, LOW); |
| 280 | digitalWrite(14, LOW); |
| 281 | digitalWrite(15, LOW); |
| 282 | digitalWrite(16, LOW); |
| 283 | digitalWrite(17, LOW); |
| 284 | // delay(300); |
| 285 | clean(); |
| 286 | |
| 287 | |
| 288 | // time 2 |
| 289 | // digitalWrite(2, HIGH); // HIGH |
| 290 | digitalWrite(3, HIGH); // HIGH |
| 291 | // digitalWrite(4, HIGH); // HIGH |
| 292 | // digitalWrite(5, HIGH); // HIGH |
| 293 | // digitalWrite(6, HIGH); // HIGH |
| 294 | // digitalWrite(7, HIGH); // HIGH |
| 295 | // digitalWrite(8, HIGH); // HIGH |
| 296 | // digitalWrite(10, LOW); |
| 297 | // digitalWrite(11, LOW); |
| 298 | // digitalWrite(12, LOW); |
| 299 | digitalWrite(13, LOW); |
| 300 | // digitalWrite(14, LOW); |
| 301 | // digitalWrite(15, LOW); |
| 302 | // digitalWrite(16, LOW); |
| 303 | // digitalWrite(17, LOW); |
| 304 | // delay(300); |
| 305 | clean(); |
| 306 | |
| 307 | // |
| 308 | // // time 3 |
| 309 | // digitalWrite(2, HIGH); // HIGH |
| 310 | // digitalWrite(3, HIGH); // HIGH |
| 311 | digitalWrite(4, HIGH); // HIGH |
| 312 | // digitalWrite(5, HIGH); // HIGH |
| 313 | // digitalWrite(6, HIGH); // HIGH |
| 314 | // digitalWrite(7, HIGH); // HIGH |
| 315 | // digitalWrite(8, HIGH); // HIGH |
| 316 | // digitalWrite(10, LOW); |
| 317 | // digitalWrite(11, LOW); |
| 318 | // digitalWrite(12, LOW); |
| 319 | digitalWrite(13, LOW); |
| 320 | // digitalWrite(14, LOW); |
| 321 | // digitalWrite(15, LOW); |
| 322 | // digitalWrite(16, LOW); |
| 323 | // digitalWrite(17, LOW); |
| 324 | // delay(300); |
| 325 | clean(); |
| 326 | // |
| 327 | |
| 328 | |
| 329 | // // time 4 |
| 330 | // digitalWrite(2, HIGH); // HIGH |
| 331 | // digitalWrite(3, HIGH); // HIGH |
| 332 | // digitalWrite(4, HIGH); // HIGH |
| 333 | digitalWrite(5, HIGH); // HIGH |
| 334 | // digitalWrite(6, HIGH); // HIGH |
| 335 | // digitalWrite(7, HIGH); // HIGH |
| 336 | // digitalWrite(8, HIGH); // HIGH |
| 337 | // digitalWrite(10, LOW); |
| 338 | // digitalWrite(11, LOW); |
| 339 | // digitalWrite(12, LOW); |
| 340 | digitalWrite(13, LOW); |
| 341 | // digitalWrite(14, LOW); |
| 342 | // digitalWrite(15, LOW); |
| 343 | // digitalWrite(16, LOW); |
| 344 | // digitalWrite(17, LOW); |
| 345 | // delay(300); |
| 346 | clean(); |
| 347 | |
| 348 | // |
| 349 | // // time 5 |
| 350 | // digitalWrite(2, HIGH); // HIGH |
| 351 | // digitalWrite(3, HIGH); // HIGH |
| 352 | // digitalWrite(4, HIGH); // HIGH |
| 353 | // digitalWrite(5, HIGH); // HIGH |
| 354 | digitalWrite(6, HIGH); // HIGH |
| 355 | digitalWrite(7, HIGH); // HIGH |
| 356 | digitalWrite(8, HIGH); // HIGH |
| 357 | digitalWrite(10, LOW); |
| 358 | digitalWrite(11, LOW); |
| 359 | digitalWrite(12, LOW); |
| 360 | digitalWrite(13, LOW); |
| 361 | digitalWrite(14, LOW); |
| 362 | digitalWrite(15, LOW); |
| 363 | digitalWrite(16, LOW); |
| 364 | digitalWrite(17, LOW); |
| 365 | // delay(300); |
| 366 | clean(); |
| 367 | // |
| 368 | // // time 6 |
| 369 | // digitalWrite(2, HIGH); // HIGH |
| 370 | // digitalWrite(3, HIGH); // HIGH |
| 371 | // digitalWrite(4, HIGH); // HIGH |
| 372 | // digitalWrite(5, HIGH); // HIGH |
| 373 | // digitalWrite(6, HIGH); // HIGH |
| 374 | digitalWrite(7, HIGH); // HIGH |
| 375 | // digitalWrite(8, HIGH); // HIGH |
| 376 | // digitalWrite(10, LOW); |
| 377 | // digitalWrite(11, LOW); |
| 378 | // digitalWrite(12, LOW); |
| 379 | digitalWrite(13, LOW); |
| 380 | // digitalWrite(14, LOW); |
| 381 | // digitalWrite(15, LOW); |
| 382 | // digitalWrite(16, LOW); |
| 383 | // digitalWrite(17, LOW); |
| 384 | // delay(300); |
| 385 | clean(); |
| 386 | // |
| 387 | // // time 7 |
| 388 | // digitalWrite(2, HIGH); // HIGH |
| 389 | // digitalWrite(3, HIGH); // HIGH |
| 390 | // digitalWrite(4, HIGH); // HIGH |
| 391 | // digitalWrite(5, HIGH); // HIGH |
| 392 | // digitalWrite(6, HIGH); // HIGH |
| 393 | // digitalWrite(7, HIGH); // HIGH |
| 394 | // digitalWrite(8, HIGH); // HIGH |
| 395 | // digitalWrite(10, LOW); |
| 396 | // digitalWrite(11, LOW); |
| 397 | // digitalWrite(12, LOW); |
| 398 | // digitalWrite(13, LOW); |
| 399 | // digitalWrite(14, LOW); |
| 400 | // digitalWrite(15, LOW); |
| 401 | // digitalWrite(16, LOW); |
| 402 | // digitalWrite(17, LOW); |
| 403 | // delay(300); |
| 404 | clean(); |
| 405 | // |
| 406 | |
| 407 | // time 8 |
| 408 | // digitalWrite(2, HIGH); // HIGH |
| 409 | // digitalWrite(3, HIGH); // HIGH |
| 410 | // digitalWrite(4, HIGH); // HIGH |
| 411 | // digitalWrite(5, HIGH); // HIGH |
| 412 | // digitalWrite(6, HIGH); // HIGH |
| 413 | // digitalWrite(7, HIGH); // HIGH |
| 414 | // digitalWrite(8, HIGH); // HIGH |
| 415 | digitalWrite(9, HIGH); // HIGH |
| 416 | digitalWrite(10, LOW); |
| 417 | digitalWrite(11, LOW); |
| 418 | digitalWrite(12, LOW); |
| 419 | digitalWrite(13, LOW); |
| 420 | digitalWrite(14, LOW); |
| 421 | digitalWrite(15, LOW); |
| 422 | digitalWrite(16, LOW); |
| 423 | digitalWrite(17, LOW); |
| 424 | clean(); |
| 425 | } |
| 426 | |
| 427 | void clean() |
| 428 | { |
| 429 | digitalWrite(2, LOW); |
| 430 | digitalWrite(3, LOW); |
| 431 | digitalWrite(4, LOW); |
| 432 | digitalWrite(5, LOW); |
| 433 | digitalWrite(6, LOW); |
| 434 | digitalWrite(7, LOW); |
| 435 | digitalWrite(8, LOW); |
| 436 | digitalWrite(9, LOW); |
| 437 | |
| 438 | digitalWrite(10, HIGH); |
| 439 | digitalWrite(11, HIGH); |
| 440 | digitalWrite(12, HIGH); |
| 441 | digitalWrite(13, HIGH); |
| 442 | digitalWrite(14, HIGH); |
| 443 | digitalWrite(15, HIGH); |
| 444 | digitalWrite(16, HIGH); |
| 445 | digitalWrite(17, HIGH); |
| 446 | } |
| 447 | }}} |