動機
那一坨套件裡面有8x8 led,那就做個會動的愛心好了
反正情人節到了
是說我以為很簡單,結果看了半天的規格還是不會弄
後來決定土砲測試哪個腳位會亮這樣
開工
不管怎樣 通通捅上去了
反正我不是專業出身的嘛 XDDDD
這邊用到的腳位是2~17
發現板子上的a0~a3 代表14~17
然後把led蓋上去
接下來做了個簡單的測試,看剛剛亂插的到底是哪個
在這之前我先做好變數定義
我開了個google試算表,然後劃出我想畫的愛心
接下來再code裡面定義
const int row1 = 2; const int row2 = 7; const int row3 = 14; const int row4 = 5; const int row5 = 13; const int row6 = 15; const int row7 = 12; const int row8 = 17; const int col1 = 6; const int col2 = 11; const int col3 = 10; const int col4 = 3; const int col5 = 16; const int col6 = 4; const int col7 = 8; const int col8 = 9;是說我剛剛不是亂插的嗎,為啥我知道哪個pin對上哪個row col
因為我做了個實驗
我先把2點亮
digitalWrite(2,1);然後幸運的發現第一排亮了,所以row1就是2了
接下來我也把pin 3 點亮
digitalWrite(2,1); digitalWrite(3,1);
col4就出來了!
接下來其他的pin跟著如法炮製就行了
動畫
接下來利用人眼視覺殘留的技巧,一行一行的亮
參照剛剛我用的試算表
這樣就會出現漂亮的心型
id heart1(){ digitalWrite(col1,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col8,1); digitalWrite(row2,1);//row2 digitalWrite(row2,0); digitalWrite(col1,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col8,0); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(row3,1);//row3 digitalWrite(row3,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col6,0); digitalWrite(col7,0); ...略可是不會動還不夠潮阿
所以我又做了一個小愛心
然後再led上面寫情人節快樂
接著讓他loop
完成!
全部的程式
#include <Wire.h> #include <LiquidCrystal_I2C.h> // Set the LCD address to 0x27 for a 16 chars and 2 line display LiquidCrystal_I2C lcd(0x27, 16, 2); const int row1 = 2; // the number of the row pin 9 const int row2 = 7; // the number of the row pin 14 const int row3 = 14; // the number of the row pin 8 const int row4 = 5; // the number of the row pin 12 const int row5 = 13; // the number of the row pin 1 const int row6 = 15; // the number of the row pin 7 const int row7 = 12; // the number of the row pin 2 const int row8 = 17; // the number of the row pin 5 const int col1 = 6; // the number of the col pin 13 const int col2 = 11; // the number of the col pin 3 const int col3 = 10; // the number of the col pin 4 const int col4 = 3; // the number of the col pin 10 const int col5 = 16; // the number of the col pin 6 const int col6 = 4; // the number of the col pin 11 const int col7 = 8; // the number of the col pin 15 const int col8 = 9; // the number of the col pin 16 void setup() { // initialize the LCD lcd.begin(); for(int i=2;i<=17;i++) { pinMode(i, OUTPUT); } } void loop() { int count; lcd.clear(); lcd.print("Happy"); lcd.setCursor(0, 1); lcd.print("Valentine's Day"); for(count=0;count<=2000;count++){ heart2(); } for(count=0;count<=2000;count++){ heart1(); } lcd.clear(); lcd.setCursor(3, 0); lcd.print("Hey Girl"); lcd.setCursor(1, 1); lcd.print("- I Love U -"); for(count=0;count<=2000;count++){ heart2(); } for(count=0;count<=2000;count++){ heart1(); } } void heart1(){ digitalWrite(col1,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col8,1); digitalWrite(row2,1); digitalWrite(row2,0); digitalWrite(col1,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col8,0); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(row3,1); digitalWrite(row3,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(row4,1); digitalWrite(row4,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(row5,1); digitalWrite(row5,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col1,1); digitalWrite(col3,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col6,1); digitalWrite(col8,1); digitalWrite(row6,1); digitalWrite(row6,0); digitalWrite(col1,0); digitalWrite(col3,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col6,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row7,1); digitalWrite(row7,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row7,1); digitalWrite(row7,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row8,1); digitalWrite(row8,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col8,0); } void heart2(){ digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col4,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row3,1); digitalWrite(row3,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col4,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col3,1); digitalWrite(col5,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row4,1); digitalWrite(row4,0); digitalWrite(col1,0); digitalWrite(col3,0); digitalWrite(col5,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col3,1); digitalWrite(col4,1); digitalWrite(col5,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row5,1); digitalWrite(row5,0); digitalWrite(col1,0); digitalWrite(col3,0); digitalWrite(col4,0); digitalWrite(col5,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col4,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row6,1); digitalWrite(row6,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col4,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col8,0); digitalWrite(col1,1); digitalWrite(col2,1); digitalWrite(col3,1); digitalWrite(col5,1); digitalWrite(col6,1); digitalWrite(col7,1); digitalWrite(col8,1); digitalWrite(row7,1); digitalWrite(row7,0); digitalWrite(col1,0); digitalWrite(col2,0); digitalWrite(col3,0); digitalWrite(col5,0); digitalWrite(col6,0); digitalWrite(col7,0); digitalWrite(col8,0); } void clear(){ }
留言
張貼留言