小紅人動畫

 #include <LedControl.h>


LedControl lc = LedControl(5, 7, 6, 1);


// 小綠人站立姿勢

byte man_stand[8] = {

  0b00011000,

  0b00011000,

  0b00011000,

  0b00111100,

  0b00111100,

  0b00011000,

  0b00100100,

  0b01000010

};


// 小綠人走路姿勢 A

byte man_walk1[8] = {

  0b00011000,

  0b00011000,

  0b00011000,

  0b00111100,

  0b00111100,

  0b00011000,

  0b00101000,

  0b01000100

};


// 小綠人走路姿勢 B

byte man_walk2[8] = {

  0b00011000,

  0b00011000,

  0b00011000,

  0b00111100,

  0b00111100,

  0b00011000,

  0b00010100,

  0b00100010

};


void setup() {

  lc.shutdown(0, false);   // 啟動顯示

  lc.setIntensity(0, 8);   // 設定亮度(0到15)

  lc.clearDisplay(0);      // 清除顯示

}


void loop() {

  // 先顯示站立

  showPattern(man_stand);

  delay(500);


  // 模擬走路:交替顯示兩種姿勢

  for (int i = 0; i < 10; i++) {

    showPattern(man_walk1);

    delay(400);

    showPattern(man_walk2);

    delay(400);

  }


  // 回到站立

  showPattern(man_stand);

  delay(1000);

}


// 顯示圖案的函式

void showPattern(byte pattern[8]) {

  for (int row = 0; row < 8; row++) {

    lc.setRow(0, row, pattern[row]);

  }

}





留言