本帖最後由 pizg 於 2011-9-5 16:34 編輯  
 
我有5顆LED燈要像闢靂車那樣逐一點亮, 字串陣列的內容是用來開關LED燈的依據, 
 
字串陣列如下 
 
String s[8] = {"00001",  "00010", "00100", "01000", "10000", "01000", "00100", "00010"}; 
 
請問要如何取出第2個元素(指標為1) 
 
"00010" 
 
的第4個字元? 
 
"1" 
 
上述問題我已自行解決, 現在新的問題是 
闢靂燈在跑了一陣子之後,  
pin 12的燈就不會亮,  
而且在更久之後所有的燈都不會亮了, 
除非按下reset鈕才能重新啟動, 
還請各位大幫忙除錯, 
 
硬體接法如下: 
 
 
 
程式碼如下: 
 
//2011-09-04 by PizG 
int pinBASE = 8; 
int LEDs = 5; 
int index = 0; 
String s1[8] = {"00001", "00010", "00100", "01000", "10000", "01000", "00100", "00010"}; 
String s2[6] = {"00011", "00110", "01100", "11000", "01100", "00110"}; 
void setup() 
{ 
  for (int i = pinBASE ; i <= 12 ; i++) pinMode(i , OUTPUT); 
}   
void loop() 
{ 
  for (int i = pinBASE ; i <= 12 ; i++) digitalWrite(i , LOW); 
  for (int i = LEDs ; i > 0 ; i--) if (s2[index].substring(i - 1 , i) == "1") digitalWrite(pinBASE + LEDs - i, HIGH);    
  delay(100);  
  index = (index + 1) % pinBASE; 
} |