Changes between Version 12 and Version 13 of wade/embedded/arduino/example/temp


Ignore:
Timestamp:
May 10, 2013, 2:53:55 PM (12 years ago)
Author:
wade
Comment:

--

Legend:

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

    v12 v13  
    345345
    346346}}}
     347
     348= 程式五:點亮左上至右下的LED =
     349{{{
     350#define start_pin 2
     351#define end_pin 18
     352#define low_start_pin 10
     353#define low_end_pin 17
     354#define high_start_pin 2
     355#define high_end_pin 9
     356#define led_delay_time 150
     357#define button 2
     358int delay_time= 0;
     359
     360void setup()
     361{
     362  for (int i=start_pin; i<=end_pin; i++)
     363  {
     364    pinMode(i, OUTPUT);
     365  }
     366  clean();
     367}
     368
     369void loop()
     370{
     371  // time 1
     372  digitalWrite(2, HIGH);
     373  digitalWrite(10, LOW);
     374  delay(delay_time);
     375  clean();
     376  delay(delay_time);
     377 
     378   // time 2
     379  digitalWrite(3, HIGH);
     380  digitalWrite(11, LOW);
     381  delay(delay_time);
     382  clean();
     383  delay(delay_time);
     384 
     385   // time 3
     386  digitalWrite(4, HIGH);
     387  digitalWrite(12, LOW);
     388  delay(delay_time);
     389  clean();
     390  delay(delay_time);
     391 
     392   // time 4
     393  digitalWrite(5, HIGH);
     394  digitalWrite(13, LOW);
     395  delay(delay_time);
     396  clean();
     397  delay(delay_time);
     398 
     399   // time 5
     400  digitalWrite(6, HIGH);
     401  digitalWrite(14, LOW);
     402  delay(delay_time);
     403  clean();
     404  delay(delay_time);
     405 
     406   // time 6
     407  digitalWrite(7, HIGH);
     408  digitalWrite(15, LOW);
     409  delay(delay_time);
     410  clean();
     411  delay(delay_time);
     412 
     413   // time 7
     414  digitalWrite(8, HIGH);
     415  digitalWrite(16, LOW);
     416  delay(delay_time);
     417  clean();
     418  delay(delay_time);
     419 
     420   // time 8
     421  digitalWrite(9, HIGH);
     422  digitalWrite(17, LOW);
     423  delay(delay_time);
     424  clean();
     425  delay(delay_time);
     426}
     427
     428void clean()
     429{
     430  Serial.println("clean");
     431  for (int i=low_start_pin; i<=low_end_pin; i++)
     432    digitalWrite(i, HIGH);
     433  for (int i=high_start_pin; i<=high_end_pin; i++)
     434    digitalWrite(i, LOW);
     435}
     436}}}