|
6#
樓主 |
發表於 2015-1-7 21:52:44
|
只看該作者
本帖最後由 mark501227 於 2015-1-7 22:01 編輯
我看懂了,但是我不知道怎麼使用這個函數,如果我要用substing()這個函數是要先宣告還是要去哪裡引用麻..?
有額外小問題,
1.為何我輸入Y沒辦法全亮,其他都正常(單獨全部打開也可),是因為需要delay還是?
2.若我要用digitalread讀取全部LED狀態丟到電腦,我是要把指令放在哪裡?因為放在loop裡面就會一直讀值
EX: ABC(全亮)放在loop裡會變成100110111
- char x;
- void setup()
- {
- Serial.begin(9600);
- for(int ledpin = 2; ledpin <=13; ledpin++)
- { pinMode(ledpin,OUTPUT); }
- }
- void loop()
- {
- if (Serial.available() > 0)
- { x = Serial.read();
- LED();
- }
- void LED(){
- switch(x)
- {
- case 'A': digitalWrite(2,HIGH); break;
- case 'M': digitalWrite(2,LOW); break;
- case 'B': digitalWrite(3,HIGH); break;
- case 'N': digitalWrite(3,LOW); break;
- case 'C': digitalWrite(4,HIGH); break;
- case 'O': digitalWrite(4,LOW); break;
- case 'D': digitalWrite(5,HIGH); break;
- case 'P': digitalWrite(5,LOW); break;
- case 'E': digitalWrite(6,HIGH); break;
- case 'Q': digitalWrite(6,LOW); break;
- case 'F': digitalWrite(7,HIGH); break;
- case 'R': digitalWrite(7,LOW); break;
- case 'G': digitalWrite(8,HIGH); break;
- case 'S': digitalWrite(8,LOW); break;
- case 'H': digitalWrite(9,HIGH); break;
- case 'T': digitalWrite(9,LOW); break;
- case 'I': digitalWrite(10,HIGH); break;
- case 'U': digitalWrite(10,LOW); break;
- case 'J': digitalWrite(11,HIGH); break;
- case 'V': digitalWrite(11,LOW); break;
- case 'K': digitalWrite(12,HIGH); break;
- case 'W': digitalWrite(12,LOW); break;
- case 'L': digitalWrite(13,HIGH); break;
- case 'X': digitalWrite(13,LOW); break;
- case 'Y': for(int ledpinON = 2; ledpinON <=13; ledpinON++)
- { pinMode(ledpinON,HIGH); } break;
- case 'Z': for(int ledpinoff = 2; ledpinoff <=13; ledpinoff++)
- { pinMode(ledpinoff,LOW); } break;
- }
- }
複製代碼 |
|