1.購買的LED尺寸規格小於預期, 48顆LED的長度才能達到60公分.因此全部的Digital pin都要用於LED使用.所以要用於作業的LED串就需要一點勞作的實力了.
一整包的LED要如何排排站好呢?用手抓,別鬧了.烙鐵溫度300度,
至於要如何快速又簡單的將LED串接起來,首先就要先設計製具,
以下直接找個瓦楞紙盒,先規劃好距離,針對LED的位置開孔.
接著貼上一層鋁箔.散熱使用,避免烙鐵直接將瓦楞紙燒毀.
瞧,排隊整齊劃一,輕輕一點錫就接合焊好,輕鬆愉快.
速度快的話20分鐘就弄出這麼多組啦.
2. MP3 module未能如期發出聲音來.可能是程式碼有問題,或是IC的使用上還需要花點時間認識.最後重新改寫控制,先刪除MP3 player的部分,並追加新的LED控制pin,以及一分鐘無任何震動後關閉的設定.
#includeint LEDstatus = 0; //定義變量為LEDstatus int Touchstatus = 0; int hum[4]; int sensorValue; int prevValue; int StopCount; const int LEDdelay = 20; //定義延遲0.020秒進行一次LED升降50FPS const int BreatheStep = 5; const int PowerSW = 0; // A0 const int WaveSW = 1; // A1 const int LEDMartix[12] = {13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2} ; //設定LED Martix const int PWMpin[12] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0}; // PWM: 3, 5, 6, 9, 10, 11. Provide 8-bit PWM output with the analogWrite() function. int CheckTouch(int AnalogPin) { prevValue = sensorValue; sensorValue = analogRead(AnalogPin); if (sensorValue >= 1023 && sensorValue >= prevValue) { return 1; } if (sensorValue < 1010 & prevValue <= 1010) { return 0; } } void SaberInital() { for (int i = 11; i >= 0; i--) { digitalWrite(LEDMartix[i], LOW); } LEDstatus = 0; StopCount = 0; } void SaberON() { for (int i = 0; i <= 11; i++) { digitalWrite(LEDMartix[i], HIGH); delay(LEDdelay); LEDstatus = 1; } } void SaberOFF() { for (int i = 11; i >= 0; i--) { digitalWrite(LEDMartix[i], LOW); delay(LEDdelay); LEDstatus = 0; } } void SaberFlickON() { for (int j = 0 ; j <= 100; j++) { for (int i = 0; i <= 11; i++) { if (i != 11) { digitalWrite(LEDMartix[i], LOW); } if (i != 0) { digitalWrite(LEDMartix[i - 1], HIGH); } } delay( LEDdelay / 2); //定義延遲0.01秒進行 } LEDstatus = 1; } void SaberBreatheON() { for (int j = 255 ; j >= 0 ; j - BreatheStep) { for (int i = 0; i <= 11; i++) { if (PWMpin[i] == 0) { if (i != 11) { digitalWrite(LEDMartix[i], LOW); } if (i != 0 || PWMpin[i - 1] != 1 ) { digitalWrite(LEDMartix[i - 1], HIGH); } } if (PWMpin[i] == 1) { analogWrite(LEDMartix[i], j); } } delay( LEDdelay); //定義延遲0.02秒進行 } for (int j = 0 ; j <= 255 ; j + BreatheStep) { for (int i = 0; i <= 11; i++) { if (PWMpin[i] == 0) { if (i != 11) { digitalWrite(LEDMartix[i], LOW); } if (i != 0 || PWMpin[i - 1] != 1 ) { digitalWrite(LEDMartix[i - 1], HIGH); } } if (PWMpin[i] == 1) { analogWrite(LEDMartix[i], j); } } delay( LEDdelay); //定義延遲0.02秒進行 } LEDstatus = 1; } void setup () { pinMode(2, OUTPUT); //設定D2為輸出端,劍尾端 pinMode(3, OUTPUT); //設定D3為輸出端 pinMode(4, OUTPUT); //設定D4為輸出端 pinMode(5, OUTPUT); //設定D5為輸出端 pinMode(6, OUTPUT); //設定D6為輸出端 pinMode(7, OUTPUT); //設定D7為輸出端 pinMode(8, OUTPUT); //設定D8為輸出端 pinMode(9, OUTPUT); //設定D9為輸出端 pinMode(10, OUTPUT); //設定D10為輸出端 pinMode(11, OUTPUT); //設定D11為輸出端 pinMode(12, OUTPUT); //設定D12為輸出端 pinMode(13, OUTPUT); //設定D13為輸出端,劍首端,接近劍柄 pinMode(A0, INPUT); //LED啟動開關接腳在A0,為輸入端 pinMode(A1, INPUT); //設定震動開關接腳在A1,為輸入端 SaberInital(); } void loop() { if (LEDstatus == 0 && CheckTouch(PowerSW) == 1) { //當有開關觸發LED亮 SaberON(); } if (LEDstatus == 1 && CheckTouch(PowerSW) == 1) { //當有開關再次觸發LED暗 SaberOFF(); } if (LEDstatus == 1) { //當光劍啟動時紀錄震動開關觸發狀態 for (int i = 0; i < 4; i++) { hum[i] = CheckTouch(WaveSW); delay(250); } if ((hum[0] != 0 && hum[1] != 0 && hum[2] != 0 && hum[3] != 0) || (hum[0] != 1 && hum[1] != 1 && hum[2] != 1 && hum[3] != 1)) { SaberFlickON(); StopCount = 0; } else { StopCount = StopCount + 1; if (StopCount >> 2400) { SaberOFF(); } } } }
沒有留言:
張貼留言