Changes between Version 4 and Version 5 of wade/embedded/arduino/example/temp


Ignore:
Timestamp:
May 8, 2013, 5:53:15 PM (12 years ago)
Author:
wade
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • wade/embedded/arduino/example/temp

    v4 v5  
    11[[PageOutline]]
    22
    3 = 程式一 =
     3= 程式一:測試程式 =
    44{{{
    5 /*
    6   Blink
    7   Turns on an LED on for one second, then off for one second, repeatedly.
    8  
    9   This example code is in the public domain.
    10  */
     5#define start_pin 2
     6#define end_pin 18
     7#define low_start_pin 10
     8#define low_end_pin 17
     9#define high_start_pin 2
     10#define high_end_pin 9
     11#define led_delay_time 150
     12#define button 2
    1113
    12 void setup() {               
    13   // initialize the digital pin as an output.
    14   // Pin 13 has an LED connected on most Arduino boards:
    15   pinMode(2, OUTPUT);
    16   pinMode(3, OUTPUT);
    17   pinMode(4, OUTPUT);
    18   pinMode(5, OUTPUT); 
    19   pinMode(6, OUTPUT);
    20   pinMode(7, OUTPUT); 
    21   pinMode(8, OUTPUT);
    22   pinMode(9, OUTPUT); 
     14boolean flag;
     15
     16void setup()
     17{
     18  for (int i=start_pin; i<=end_pin; i++)
     19  {
     20    pinMode(i, OUTPUT);
     21  }
     22//  pinMode(button, INPUT);
     23//  digitalWrite(button, HIGH);
     24//  attachInterrupt(0, button_event, LOW);
     25  Serial.begin(9600);
     26  clean();
    2327}
    2428
    25 void loop() {
    26   digitalWrite(2, HIGH);   // set the LED on
    27   delay(300);              // wait for a second
    28   digitalWrite(2, LOW);    // set the LED off
    29   delay(300);              // wait for a second
    30  
    31   digitalWrite(3, HIGH);   // set the LED on
    32   delay(300);              // wait for a second
    33   digitalWrite(3, LOW);    // set the LED off
    34   delay(300);              // wait for a second
    35  
    36   digitalWrite(4, HIGH);   // set the LED on
    37   delay(300);              // wait for a second
    38   digitalWrite(4, LOW);    // set the LED off
    39   delay(300);              // wait for a second
    40  
    41   digitalWrite(5, HIGH);   // set the LED on
    42   delay(300);              // wait for a second
    43   digitalWrite(5, LOW);    // set the LED off
    44   delay(300);              // wait for a second
    45  
    46   digitalWrite(6, HIGH);   // set the LED on
    47   delay(300);              // wait for a second
    48   digitalWrite(6, LOW);    // set the LED off
    49   delay(300);              // wait for a second
    50  
    51   digitalWrite(7, HIGH);   // set the LED on
    52   delay(300);              // wait for a second
    53   digitalWrite(7, LOW);    // set the LED off
    54   delay(300);              // wait for a second
    55  
    56   digitalWrite(8, HIGH);   // set the LED on
    57   delay(300);              // wait for a second
    58   digitalWrite(8, LOW);    // set the LED off
    59   delay(300);              // wait for a second
    60  
    61   digitalWrite(9, HIGH);   // set the LED on
    62   delay(300);              // wait for a second
    63   digitalWrite(9, LOW);    // set the LED off
    64   delay(300);              // wait for a second
    65  
    66 }
    67 }}}
    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);
     29void loop()
     30{
    13531  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();
     32  delay(led_delay_time);
     33  for (int i=high_start_pin; i<=high_end_pin; i++)
     34  {
     35    Serial.print("[");
     36    Serial.print(i);
     37    Serial.println("]  ");
     38    digitalWrite(i, HIGH);
     39    for (int j=low_start_pin; j<=low_end_pin; j++)
     40    {
     41      Serial.print("  ");
     42      Serial.print(j);
     43      digitalWrite(j, LOW);
     44      delay(led_delay_time);
     45      digitalWrite(j, HIGH);
     46    }
     47    Serial.println();
     48    digitalWrite(i, LOW);
     49  }
    19450}
    19551
    19652void clean()
    19753{
    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);
     54  Serial.println("clean");
     55  for (int i=low_start_pin; i<=low_end_pin; i++)
     56    digitalWrite(i, HIGH);
     57  for (int i=high_start_pin; i<=high_end_pin; i++)
     58    digitalWrite(i, LOW);
     59}
     60
     61void button_event()
     62{
     63  delay(500);
     64  flag = !flag;
     65  while(flag)
     66  {
     67  }
    21568}
    21669}}}
    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(9, HIGH);   // HIGH
    277   digitalWrite(10, LOW);
    278   digitalWrite(11, LOW);
    279   digitalWrite(12, LOW);
    280   digitalWrite(13, LOW);
    281   digitalWrite(14, LOW);
    282   digitalWrite(15, LOW);
    283   digitalWrite(16, LOW);
    284   digitalWrite(17, LOW);
    285 //  delay(300);
    286   clean();
    287  
    288    
    289   // time 2
    290 //  digitalWrite(2, HIGH);   // HIGH
    291   digitalWrite(3, HIGH);   // HIGH
    292 //  digitalWrite(4, HIGH);   // HIGH
    293 //  digitalWrite(5, HIGH);   // HIGH
    294 //  digitalWrite(6, HIGH);   // HIGH
    295 //  digitalWrite(7, HIGH);   // HIGH
    296 //  digitalWrite(8, HIGH);   // HIGH
    297 //  digitalWrite(9, HIGH);   // HIGH
    298 //  digitalWrite(10, LOW);
    299 //  digitalWrite(11, LOW);
    300 //  digitalWrite(12, LOW);
    301   digitalWrite(13, LOW);
    302 //  digitalWrite(14, LOW);
    303 //  digitalWrite(15, LOW);
    304 //  digitalWrite(16, LOW);
    305 //  digitalWrite(17, LOW);
    306 //  delay(300);
    307   clean();
    308 
    309 // 
    310 //  // time 3
    311 //  digitalWrite(2, HIGH);   // HIGH
    312 //  digitalWrite(3, HIGH);   // HIGH
    313   digitalWrite(4, HIGH);   // HIGH
    314 //  digitalWrite(5, HIGH);   // HIGH
    315 //  digitalWrite(6, HIGH);   // HIGH
    316 //  digitalWrite(7, HIGH);   // HIGH
    317 //  digitalWrite(8, HIGH);   // HIGH
    318 //  digitalWrite(9, HIGH);   // HIGH
    319 //  digitalWrite(10, LOW);
    320 //  digitalWrite(11, LOW);
    321 //  digitalWrite(12, LOW);
    322   digitalWrite(13, LOW);
    323 //  digitalWrite(14, LOW);
    324 //  digitalWrite(15, LOW);
    325 //  digitalWrite(16, LOW);
    326 //  digitalWrite(17, LOW);
    327 //  delay(300);
    328   clean();
    329 //
    330 
    331 
    332 //  // time 4
    333 //  digitalWrite(2, HIGH);   // HIGH
    334 //  digitalWrite(3, HIGH);   // HIGH
    335 //  digitalWrite(4, HIGH);   // HIGH
    336   digitalWrite(5, HIGH);   // HIGH
    337 //  digitalWrite(6, HIGH);   // HIGH
    338 //  digitalWrite(7, HIGH);   // HIGH
    339 //  digitalWrite(8, HIGH);   // HIGH
    340 //  digitalWrite(10, LOW);
    341 //  digitalWrite(11, LOW);
    342 //  digitalWrite(12, LOW);
    343   digitalWrite(13, LOW);
    344 //  digitalWrite(14, LOW);
    345 //  digitalWrite(15, LOW);
    346 //  digitalWrite(16, LOW);
    347 //  digitalWrite(17, LOW);
    348 //  delay(300);
    349   clean();
    350 
    351 // 
    352 //  // time 5
    353 //  digitalWrite(2, HIGH);   // HIGH
    354 //  digitalWrite(3, HIGH);   // HIGH
    355 //  digitalWrite(4, HIGH);   // HIGH
    356 //  digitalWrite(5, HIGH);   // HIGH
    357   digitalWrite(6, HIGH);   // HIGH
    358 //  digitalWrite(7, HIGH);   // HIGH
    359 //  digitalWrite(8, HIGH);   // HIGH
    360   digitalWrite(10, LOW);
    361   digitalWrite(11, LOW);
    362   digitalWrite(12, LOW);
    363   digitalWrite(13, LOW);
    364   digitalWrite(14, LOW);
    365   digitalWrite(15, LOW);
    366   digitalWrite(16, LOW);
    367   digitalWrite(17, LOW);
    368 //  delay(300);
    369   clean();
    370 // 
    371 //  // time 6
    372 //  digitalWrite(2, HIGH);   // HIGH
    373 //  digitalWrite(3, HIGH);   // HIGH
    374 //  digitalWrite(4, HIGH);   // HIGH
    375 //  digitalWrite(5, HIGH);   // HIGH
    376 //  digitalWrite(6, HIGH);   // HIGH
    377   digitalWrite(7, HIGH);   // HIGH
    378 //  digitalWrite(8, HIGH);   // HIGH
    379 //  digitalWrite(10, LOW);
    380 //  digitalWrite(11, LOW);
    381 //  digitalWrite(12, LOW);
    382   digitalWrite(13, LOW);
    383 //  digitalWrite(14, LOW);
    384 //  digitalWrite(15, LOW);
    385 //  digitalWrite(16, LOW);
    386 //  digitalWrite(17, LOW);
    387 //  delay(300);
    388   clean();
    389 // 
    390 //  // time 7
    391 //  digitalWrite(2, HIGH);   // HIGH
    392 //  digitalWrite(3, HIGH);   // HIGH
    393 //  digitalWrite(4, HIGH);   // HIGH
    394 //  digitalWrite(5, HIGH);   // HIGH
    395 //  digitalWrite(6, HIGH);   // HIGH
    396 //  digitalWrite(7, HIGH);   // HIGH
    397   digitalWrite(8, HIGH);   // HIGH
    398 //    digitalWrite(9, HIGH);   // HIGH
    399 //  digitalWrite(10, LOW);
    400 //  digitalWrite(11, LOW);
    401 //  digitalWrite(12, LOW);
    402   digitalWrite(13, LOW);
    403 //  digitalWrite(14, LOW);
    404 //  digitalWrite(15, LOW);
    405 //  digitalWrite(16, LOW);
    406 //  digitalWrite(17, LOW);
    407 //  delay(300);
    408   clean();
    409 // 
    410 
    411   // time 8
    412 //  digitalWrite(2, HIGH);   // HIGH
    413 //  digitalWrite(3, HIGH);   // HIGH
    414 //  digitalWrite(4, HIGH);   // HIGH
    415 //  digitalWrite(5, HIGH);   // HIGH
    416 //  digitalWrite(6, HIGH);   // HIGH
    417 //  digitalWrite(7, HIGH);   // HIGH
    418 //  digitalWrite(8, HIGH);   // HIGH
    419   digitalWrite(9, HIGH);   // HIGH
    420   digitalWrite(10, LOW);
    421   digitalWrite(11, LOW);
    422   digitalWrite(12, LOW);
    423   digitalWrite(13, LOW);
    424   digitalWrite(14, LOW);
    425   digitalWrite(15, LOW);
    426   digitalWrite(16, LOW);
    427   digitalWrite(17, LOW);
    428   clean();
    429 }
    430 
    431 void clean()
    432 {
    433   delay(300);
    434   digitalWrite(2, LOW);
    435   digitalWrite(3, LOW);
    436   digitalWrite(4, LOW);
    437   digitalWrite(5, LOW);
    438   digitalWrite(6, LOW);
    439   digitalWrite(7, LOW);
    440   digitalWrite(8, LOW);
    441   digitalWrite(9, LOW);
    442  
    443   digitalWrite(10, HIGH);
    444   digitalWrite(11, HIGH);
    445   digitalWrite(12, HIGH);
    446   digitalWrite(13, HIGH);
    447   digitalWrite(14, HIGH);
    448   digitalWrite(15, HIGH);
    449   digitalWrite(16, HIGH);
    450   digitalWrite(17, HIGH);
    451 }
    452 }}}