// 2017/11/2 // Faya-Nugget 範例程式 (Serial8x8Dot_2.ino) // 單元: 模組介紹 :faya 串列8x8點矩陣模組 // 網址: // 目標 (1) 在8x8矩陣顯示器上隨機顯示剪刀石頭布 // (2) 按下觸控開關時,顯示當時的圖騰3秒鐘 // 接線: Arduino ==> faya模組 // D10 ==> LOAD (8*8矩陣顯示器模組) // D11 ==> CLK (8*8矩陣顯示器模組) // D12 ==> DIN (8*8矩陣顯示器模組) // A0 ==> OUT (觸控開關) #include "LedControl.h" #define button A0 //定義Arduino與七字節模組的連接腳位與參數 LedControl fayaSerial8x8Dot = LedControl(12,11,10,1); boolean scissor[8][8] = //剪刀圖騰 { {0,0,0,1,0,1,0,0}, {0,0,0,1,0,1,0,0}, {0,0,0,1,0,1,0,0}, {0,1,1,1,1,1,1,0}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,0}, {0,1,1,1,1,1,0,0}, {0,0,1,1,1,0,0,0} }; boolean stone[8][8] = //石頭圖騰 { {0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0}, {0,0,1,1,1,1,0,0}, {0,1,1,1,1,1,1,0}, {1,1,1,1,1,1,1,1}, {1,1,1,1,1,1,1,1}, {0,1,1,1,1,1,1,0}, {0,0,1,1,1,0,0,0} }; boolean paper[8][8] = //布圖騰 { {0,0,1,0,1,0,0,0}, {1,0,1,0,1,0,1,0}, {1,0,1,0,1,0,1,0}, {1,1,1,1,1,1,1,0}, {1,1,1,1,1,1,1,0}, {1,1,1,1,1,1,1,1}, {0,1,1,1,1,1,0,0}, {0,0,1,1,1,0,0,0} }; int result; //儲存圖騰結果 void setup() { fayaSerial8x8Dot.shutdown(0,false); // 初始化 fayaSerial8x8Dot.setIntensity(0,10); // 設定亮度 fayaSerial8x8Dot.clearDisplay(0); // 清除畫面 pinMode(button, INPUT); } void loop() { randomSeed(analogRead(5)); //取得亂數種子 result = random(1,4); //1~3中亂數取一值 switch (result) { case 1: // 1出剪刀 show_scissor(); break; case 2: show_stone(); // 2出石頭 break; case 3: show_paper(); // 3出布 break; default: // if nothing else matches, do the default // default is optional break; } delay(50); // 每次顯示間隔0.05秒 if(digitalRead(button) == HIGH) { //當按下按鍵時 delay(3000); //最後一次的圖示停留三秒 } } void show_scissor() //顯示剪刀圖示 { for(int i=0; i<=7; i++) { for (int j=0; j<=7; j++) { fayaSerial8x8Dot.setLed(0,j,i,scissor[i][j]); } } } void show_stone() //顯示石頭圖示 { for(int i=0; i<=7; i++) { for (int j=0; j<=7; j++) { fayaSerial8x8Dot.setLed(0,j,i,stone[i][j]); } } } void show_paper() //顯示布圖示 { for(int i=0; i<=7; i++) { for (int j=0; j<=7; j++) { fayaSerial8x8Dot.setLed(0,j,i,paper[i][j]); } } }