wiki:wade/embedded/arduino/example/temp

Version 6 (modified by wade, 12 years ago) (diff)

--

程式一:LED 矩陣測試程式

#define start_pin 2
#define end_pin 18
#define low_start_pin 10
#define low_end_pin 17
#define high_start_pin 2
#define high_end_pin 9
#define led_delay_time 150
#define button 2

boolean flag;

void setup()
{
  for (int i=start_pin; i<=end_pin; i++)
  {
    pinMode(i, OUTPUT);
  }
//  pinMode(button, INPUT);
//  digitalWrite(button, HIGH);
//  attachInterrupt(0, button_event, LOW);
  Serial.begin(9600);
  clean();
}

void loop()
{
  clean();
  delay(led_delay_time);
  for (int i=high_start_pin; i<=high_end_pin; i++)
  {
    Serial.print("[");
    Serial.print(i);
    Serial.println("]  ");
    digitalWrite(i, HIGH);
    for (int j=low_start_pin; j<=low_end_pin; j++)
    {
      Serial.print("  ");
      Serial.print(j);
      digitalWrite(j, LOW);
      delay(led_delay_time);
      digitalWrite(j, HIGH);
    }
    Serial.println();
    digitalWrite(i, LOW);
  }
}

void clean()
{
  Serial.println("clean");
  for (int i=low_start_pin; i<=low_end_pin; i++)
    digitalWrite(i, HIGH);
  for (int i=high_start_pin; i<=high_end_pin; i++)
    digitalWrite(i, LOW);
}

void button_event()
{
  delay(500);
  flag = !flag;
  while(flag)
  {
  }
}

Attachments (5)