LED Strip Controller Busted

經過專業電表工程師的測試和專業判斷,發現 “LED Strip Controller” by Rehaan33(https://www.instructables.com/LED-Strip-Controller... ) 的程式碼似乎有錯誤,導致LED燈無法正常亮起來。最後一步驟將會探討如何判斷是程式碼的錯誤。
Supplies
1. LCD 20x04 Screen (LCD螢幕)
2. Breadboard (麵包板)
3. Jumper Cables 21 male to male, 4 male to female(杜邦線 21條公對公 4條母對母)
4. Arduino USB Cable(Arduino USB 線)
5. Large PTM Buttons x4
6. Small PTM Bottons x2
7. 12V 1A Adapter(12V 1A 變壓器)
8. 1m LED Strip Light(一公尺LED燈條)
9. Wire Welding Gun(電子焊接工具)
10. 10k Ohm x6(六個10k電阻)
Step 1: 焊接按鈕



因為圖中這種按鈕不能直接插進去麵包板,所以需要將六個大小按鈕都焊接上兩個杜邦線的頭。
Step 2: 安插大按鈕




將杜邦線和四個大按鈕照著指示圖安裝。第一張圖中有有關圖示的註釋。
Step 3: 插上小按鈕




Step 4: 安裝LCD螢幕



照指示圖安插線和LCD螢幕。
如果開發版上的GND孔不夠插,就差在前幾個步驟有連到GND電阻的同一條,因為直排都是有連接的。
Step 5: 安裝LED燈條


將LED燈條和杜邦線照指示圖連接。
Step 6: 程式碼


將USB線和變壓器都插上後,到以下兩個網址下載連結:
https://github.com/johnrickman/LiquidCrystal_I2C
https://github.com/FastLED/FastLED
下載好後,解壓縮兩個zip。解壓縮完,到Arduino App上面點選「工具」->「管理程式庫」->分別搜尋「Lipiud Crystal」和「Fast LED」下載並更新。
更新完後,複製以下程式碼到Arduino App,或點選以下連結下載程式碼。(來源:LED Strip Controller by Rehaan33)
https://create.arduino.cc/editor/fionakuo0125/6788...
//2020 August 16th
//Created by Rehaan Irani //Credit: FastLED
#include
int x = 0; int one = 0; int two = 0; int three = 0; int speed = 20;
#define num 200 #define pin 6
CRGBPalette16 currentPalette; TBlendType currentBlending;
CRGB led[num];
// Include the libraries: // LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C #include // Library for I2C communication #include // Library for LCD LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
void setup() {
FastLED.addLeds(led, num); Serial.begin(9600); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(12, INPUT); pinMode(13, INPUT); lcd.init(); lcd.backlight(); }
void loop() { if (x == 0){ lcd.setCursor(0, 0); lcd.print("LED STRIP CONTROLLER"); lcd.setCursor(6, 1); lcd.print("Setting?"); lcd.setCursor(2, 2); lcd.print("BLUE"); lcd.setCursor(2, 3); lcd.print("RED"); lcd.setCursor(13, 2); lcd.print("GREEN"); lcd.setCursor(13, 3); lcd.print("OTHER"); delay(10);
if (digitalRead(8) == HIGH){//BLUE x =+ 11; one =+ 0; two =+ 255; three =+ 0; delay(100); }
if (digitalRead(9) == HIGH){ //GREEN x =+ 12; one =+ 255; two =+ 0; three =+ 0; delay(1000); } if (digitalRead(10) == HIGH){//RED x =+ 13; one =+ 0; two =+ 0; three =+ 255; delay(1000); }
if (digitalRead(11) == HIGH) { x =+ 4; delay(1000); }
}
if (x > 10) { lcd.setCursor(2, 2); lcd.print("STATIONARY"); lcd.setCursor(2, 3); lcd.print("BLINK"); lcd.setCursor(13, 2); lcd.print("FADE "); lcd.setCursor(13, 3); lcd.print("CHASE");
if (digitalRead(8) == HIGH){//STATIONARY Serial.print("HELLO"); for (int i = 0; i < num; i++) { led[i] = CRGB(one,two,three); } FastLED.show(); }
if (digitalRead(9) == HIGH){//BLINK for (;;) { if (x > 10) { if (digitalRead(13) == HIGH) { speed -= 15; } }
if (digitalRead(12) == HIGH) { Serial.print("YES"); speed += 15; } for (int i = 0; i < num; i++) { led[i] = CRGB(one,two,three); } FastLED.show(); delay(speed); for (int i = 0; i < num; i++) { led[i] = CRGB(0,0,0); } FastLED.show(); delay(speed); Serial.print(speed); Serial .print(" "); } }
if (digitalRead(10) == HIGH){//FADE for (;;) { for (int i = 255; i > 0; i--) { setColour(i); delay(speed);
if (x > 10) { if (digitalRead(13) == HIGH) { speed -= 15; } }
if (digitalRead(12) == HIGH) { Serial.print("YES"); speed += 15; } } for (int i = 0; i < 256; i++) { setColour(i); delay(speed);
if (x > 10) { if (digitalRead(13) == HIGH) { speed -= 15; } }
if (digitalRead(12) == HIGH) { Serial.print("YES"); speed += 15; } } } }
if (digitalRead(11) == HIGH){//CHASE for (;;) { for (int i = 0; i < num; i++) { led[i] = CRGB(one,two,three); FastLED.show(); led[i] = CRGB::Black; delay(speed);
if (x > 10) { if (digitalRead(13) == HIGH) { speed -= 15; } }
if (digitalRead(12) == HIGH) { Serial.print("YES"); speed += 15; } } } } }
if (x == 4) { lcd.setCursor(0, 0); lcd.print("LED STRIP CONTROLLER"); lcd.setCursor(4, 1); lcd.print("OTHER SETTING"); lcd.setCursor(2, 2); lcd.print("PARTY"); lcd.setCursor(2, 3); lcd.print("OCEAN"); lcd.setCursor(12, 2); lcd.print("PARADISE"); lcd.setCursor(12, 3); lcd.print("CLOUDY"); if (digitalRead(8) == HIGH){//PARTY x =+ 10; for (;;) { static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ FillLEDsFromPaletteColorsP(startIndex); FastLED.show(); FastLED.delay(speed); } }
if (digitalRead(9) == HIGH){//OCEAN x =+ 11; for (;;) { static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ FillLEDsFromPaletteColorsO(startIndex); FastLED.show(); FastLED.delay(speed); } }
if (digitalRead(10) == HIGH){//PARADISE x =+ 12; for (;;) { static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ FillLEDsFromPaletteColorsF(startIndex); FastLED.show(); FastLED.delay(speed); } }
if (digitalRead(11) == HIGH){//CLOUDY x =+ 13; for (;;) { static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ FillLEDsFromPaletteColorsC(startIndex); FastLED.show(); FastLED.delay(speed); } }
} }
void setColour(int val) { for (int i = 0; i < num; i++) { if (one > 0) { led[i] = CRGB(val,0,0); }
if (two > 0) { led[i] = CRGB(0,val,0); }
if (three > 0) { led[i] = CRGB(0,0,val); } }
FastLED.show(); }
void pride() { static uint16_t sPseudotime = 0; static uint16_t sLastMillis = 0; static uint16_t sHue16 = 0; uint8_t sat8 = beatsin88( 87, 220, 250); uint8_t brightdepth = beatsin88( 341, 96, 224); uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256)); uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256; uint16_t hueinc16 = beatsin88(113, 1, 3000); uint16_t ms = millis(); uint16_t deltams = ms - sLastMillis ; sLastMillis = ms; sPseudotime += deltams * msmultiplier; sHue16 += deltams * beatsin88( 400, 5,9); uint16_t brightnesstheta16 = sPseudotime; for( uint16_t i = 0 ; i < num; i++) { hue16 += hueinc16; uint8_t hue8 = hue16 / 256;
brightnesstheta16 += brightnessthetainc16; uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536; uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536; bri8 += (255 - brightdepth); CRGB newcolor = CHSV( hue8, sat8, bri8); uint16_t pixelnumber = i; pixelnumber = (num-1) - pixelnumber; nblend( led[pixelnumber], newcolor, 64); } }
void FillLEDsFromPaletteColorsO( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < num; i++) { led[i] = ColorFromPalette( OceanColors_p, colorIndex, brightness, currentBlending); colorIndex += 3; } }
void FillLEDsFromPaletteColorsP( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < num; i++) { led[i] = ColorFromPalette( PartyColors_p, colorIndex, brightness, currentBlending); colorIndex += 3; } }
void FillLEDsFromPaletteColorsF( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < num; i++) { led[i] = ColorFromPalette( ForestColors_p, colorIndex, brightness, currentBlending); colorIndex += 3; } }
void FillLEDsFromPaletteColorsC( uint8_t colorIndex) { uint8_t brightness = 255; for( int i = 0; i < num; i++) { led[i] = ColorFromPalette( CloudColors_p, colorIndex, brightness, currentBlending); colorIndex += 3; } }
Step 7: 判斷錯誤
上傳程式碼後,會發現燈條只能短暫發光不到一秒,而應該出現英文字母"LED STRIP CONTROLLER",也沒有出現。
如何判斷錯誤:
1. 用電流電壓器去觸碰電流會通過的杜邦線接頭,像是LED燈條和電線的接觸點,儀器會顯示12V,表示電流有通過,但是燈沒亮。因此表示應該是程式碼有錯誤。
2. 燈在USB剛連上電腦時有短暫閃爍,表示燈本身沒有問題。
3. 經過再三確認,所有電線所連接位置都與原作提供的圖表位置相同。