| 68 | |
| 69 | = 程式二 = |
| 70 | {{{ |
| 71 | /* |
| 72 | Blink |
| 73 | Turns on an LED on for one second, then off for one second, repeatedly. |
| 74 | |
| 75 | This example code is in the public domain. |
| 76 | */ |
| 77 | |
| 78 | void setup() { |
| 79 | // initialize the digital pin as an output. |
| 80 | // Pin 13 has an LED connected on most Arduino boards: |
| 81 | pinMode(2, OUTPUT); |
| 82 | pinMode(3, OUTPUT); |
| 83 | pinMode(4, OUTPUT); |
| 84 | pinMode(5, OUTPUT); |
| 85 | pinMode(6, OUTPUT); |
| 86 | pinMode(7, OUTPUT); |
| 87 | pinMode(8, OUTPUT); |
| 88 | pinMode(9, OUTPUT); |
| 89 | digitalWrite(2, LOW); |
| 90 | digitalWrite(3, LOW); |
| 91 | digitalWrite(4, LOW); |
| 92 | digitalWrite(5, LOW); |
| 93 | digitalWrite(6, LOW); |
| 94 | digitalWrite(7, LOW); |
| 95 | digitalWrite(8, LOW); |
| 96 | digitalWrite(9, LOW); |
| 97 | |
| 98 | pinMode(10, OUTPUT); |
| 99 | pinMode(11, OUTPUT); |
| 100 | pinMode(12, OUTPUT); |
| 101 | pinMode(13, OUTPUT); |
| 102 | pinMode(14, OUTPUT); |
| 103 | pinMode(15, OUTPUT); |
| 104 | pinMode(16, OUTPUT); |
| 105 | pinMode(17, OUTPUT); |
| 106 | digitalWrite(10, HIGH); |
| 107 | digitalWrite(11, HIGH); |
| 108 | digitalWrite(12, HIGH); |
| 109 | digitalWrite(13, HIGH); |
| 110 | digitalWrite(14, HIGH); |
| 111 | digitalWrite(15, HIGH); |
| 112 | digitalWrite(16, HIGH); |
| 113 | digitalWrite(17, HIGH); |
| 114 | } |
| 115 | |
| 116 | void loop() { |
| 117 | |
| 118 | // time 1 |
| 119 | digitalWrite(2, HIGH); // HIGH |
| 120 | // digitalWrite(3, HIGH); // HIGH |
| 121 | // digitalWrite(4, HIGH); // HIGH |
| 122 | // digitalWrite(5, HIGH); // HIGH |
| 123 | // digitalWrite(6, HIGH); // HIGH |
| 124 | // digitalWrite(7, HIGH); // HIGH |
| 125 | // digitalWrite(8, HIGH); // HIGH |
| 126 | digitalWrite(10, LOW); |
| 127 | digitalWrite(11, LOW); |
| 128 | digitalWrite(12, LOW); |
| 129 | digitalWrite(13, LOW); |
| 130 | digitalWrite(14, LOW); |
| 131 | digitalWrite(15, LOW); |
| 132 | digitalWrite(16, LOW); |
| 133 | digitalWrite(17, LOW); |
| 134 | // delay(300); |
| 135 | clean(); |
| 136 | |
| 137 | |
| 138 | // time 2 |
| 139 | // digitalWrite(3, HIGH); // HIGH |
| 140 | // delay(300); // wait for a second |
| 141 | // digitalWrite(3, LOW); // set the LED off |
| 142 | // delay(300); // wait for a second |
| 143 | // |
| 144 | // // time 3 |
| 145 | // digitalWrite(4, HIGH); // set the LED on |
| 146 | // delay(300); // wait for a second |
| 147 | // digitalWrite(4, LOW); // set the LED off |
| 148 | // delay(300); // wait for a second |
| 149 | // |
| 150 | // // time 4 |
| 151 | // digitalWrite(5, HIGH); // set the LED on |
| 152 | // delay(300); // wait for a second |
| 153 | // digitalWrite(5, LOW); // set the LED off |
| 154 | // delay(300); // wait for a second |
| 155 | // |
| 156 | // // time 5 |
| 157 | // digitalWrite(6, HIGH); // set the LED on |
| 158 | // delay(300); // wait for a second |
| 159 | // digitalWrite(6, LOW); // set the LED off |
| 160 | // delay(300); // wait for a second |
| 161 | // |
| 162 | // // time 6 |
| 163 | // digitalWrite(7, HIGH); // set the LED on |
| 164 | // delay(300); // wait for a second |
| 165 | // digitalWrite(7, LOW); // set the LED off |
| 166 | // delay(300); // wait for a second |
| 167 | // |
| 168 | // // time 7 |
| 169 | // digitalWrite(8, HIGH); // set the LED on |
| 170 | // delay(300); // wait for a second |
| 171 | // digitalWrite(8, LOW); // set the LED off |
| 172 | // delay(300); // wait for a second |
| 173 | // |
| 174 | |
| 175 | // time 8 |
| 176 | // digitalWrite(2, HIGH); // HIGH |
| 177 | // digitalWrite(3, HIGH); // HIGH |
| 178 | // digitalWrite(4, HIGH); // HIGH |
| 179 | // digitalWrite(5, HIGH); // HIGH |
| 180 | // digitalWrite(6, HIGH); // HIGH |
| 181 | // digitalWrite(7, HIGH); // HIGH |
| 182 | // digitalWrite(8, HIGH); // HIGH |
| 183 | digitalWrite(9, HIGH); // HIGH |
| 184 | digitalWrite(10, LOW); |
| 185 | digitalWrite(11, LOW); |
| 186 | digitalWrite(12, LOW); |
| 187 | digitalWrite(13, LOW); |
| 188 | digitalWrite(14, LOW); |
| 189 | digitalWrite(15, LOW); |
| 190 | digitalWrite(16, LOW); |
| 191 | digitalWrite(17, LOW); |
| 192 | // delay(300); |
| 193 | clean(); |
| 194 | } |
| 195 | |
| 196 | void clean() |
| 197 | { |
| 198 | digitalWrite(2, LOW); |
| 199 | digitalWrite(3, LOW); |
| 200 | digitalWrite(4, LOW); |
| 201 | digitalWrite(5, LOW); |
| 202 | digitalWrite(6, LOW); |
| 203 | digitalWrite(7, LOW); |
| 204 | digitalWrite(8, LOW); |
| 205 | digitalWrite(9, LOW); |
| 206 | |
| 207 | digitalWrite(10, HIGH); |
| 208 | digitalWrite(11, HIGH); |
| 209 | digitalWrite(12, HIGH); |
| 210 | digitalWrite(13, HIGH); |
| 211 | digitalWrite(14, HIGH); |
| 212 | digitalWrite(15, HIGH); |
| 213 | digitalWrite(16, HIGH); |
| 214 | digitalWrite(17, HIGH); |
| 215 | } |
| 216 | }}} |