wiki:wade/embedded/arduino/example/example_3

Version 1 (modified by wade, 15 years ago) (diff)

--

/*
 * 由 11 pins 控制 8 * 8 矩陣式 led matrix
 */

#define pin0 0             // 定義 LED 腳位
#define pin1 1             // 定義 LED 腳位
#define pin2 2            // 定義 LED 腳位
#define delay_time 500    // 定義延遲時間

// 初始設定
void setup()
{
  pinMode(pin0 , OUTPUT);
  pinMode(pin1 , OUTPUT);
  pinMode(pin2 , OUTPUT);
  digitalWrite(pin0, LOW);
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, LOW);
}

// 主程式迴圈
void loop()
{
  // HEX 000
  digitalWrite(pin0, LOW);
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, LOW);
  delay(delay_time);
  
  // HEX 001
  digitalWrite(pin0, HIGH);
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, LOW);
  delay(delay_time);

  // HEX 010
  digitalWrite(pin0, LOW);
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
  delay(delay_time);

  // HEX 011
  digitalWrite(pin0, HIGH);
  digitalWrite(pin1, HIGH);
  digitalWrite(pin2, LOW);
  delay(delay_time);
  
  // HEX 100
  digitalWrite(pin0, LOW);
  digitalWrite(pin1, LOW);
  digitalWrite(pin2, HIGH);
  delay(delay_time);  
}