作者sdsd65676 (翻桌ING)
看板ASM
標題[請益] Arduino程式請教
時間Tue Jan 16 07:22:38 2018
各位先進好,小弟是剛接觸Arduino的新手
因為專題需求自己寫了程式碼,但是遇到了一些問題。
先附上我的程式碼
int a = 3;
int b = 2;
int c = 4;
int d = 7;
int e = 8;
int f = 12;
void setup() {
// put your setup code here, to run once:
pinMode(a, INPUT); //鑰匙開關;
pinMode(b, INPUT); //檔位開關;
pinMode(c, INPUT); //距離感知器;
pinMode(d, INPUT); //靜音開關;
pinMode(e, OUTPUT); //無聲輸出;
pinMode(f, OUTPUT); //有聲輸出;
if (digitalRead (a == HIGH), digitalRead(b == HIGH)
, digitalRead(d == HIGH)) //紅火 P檔 靜音, 無聲輸出;
{
digitalWrite(e, HIGH);
delay(250);
digitalWrite(e, LOW);
delay(250);
}
if ( digitalRead (a == HIGH ), digitalRead(b == HIGH
, digitalRead(d == LOW)); //紅火 P檔 有聲, 有聲輸出;
{
digitalWrite(f, HIGH);
delay(250);
digitalWrite(f, LOW);
delay(250);
loop;
}
if ( digitalRead ([code]
if ( digitalRead (a == LOW ), digitalRead (b == HIGH)
, digitalRead (d == HIGH)); //熄火 P檔 靜音, 無聲輸出5秒;
{
digitalWrite(e, HIGH);
delay(5000);
digitalWrite(e, LOW);
delay(500);
digitalWrite(e, HIGH);
delay(500);
digitalWrite(e, LOW);
delay(500);
digitalWrite(e, HIGH);
delay(500);
digitalWrite(e, LOW);
delay(500);
digitalWrite(e, HIGH);
delay(500);
digitalWrite(e, LOW);
delay(500);
digitalWrite(e, HIGH);
[code]
delay(500);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
}
if ( digitalRead (a == LOW ), digitalRead (b == HIGH )
, digitalRead (d == LOW )); //熄火 P檔 有聲, 有聲輸出5秒;
{
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
delay(5000);
digitalWrite(f, LOW);
delay(500);
digitalWrite(f, HIGH);
delay(500);
digitalWrite(f, LOW);
delay(500);
digitalWrite(f, HIGH);
delay(500);
digitalWrite(f, LOW);
delay(500);
digitalWrite(f, HIGH);
delay(500);
digitalWrite(f, LOW);
delay(500);
digitalWrite(f, HIGH);
delay(500);
digitalWrite(f, LOW);
}
if ( digitalRead (a == HIGH ), digitalRead (b == LOW ));
{
digitalWrite(e, LOW);
digitalWrite(f, LOW);
}
}
void loop() {
// put your main code here, to run repeatedly:
pinMode(LED_BUILTIN, HIGH);
delay(100);
pinMode(LED_BUILTIN, LOW);
delay(100);
目前遇到的問題是,前兩段程式碼(紅火、P檔、有無聲輸出)不會跑到
也有試過不同的寫法,都會不作用就跳到第三段
使用的板子是 Uno R3
再次謝謝幫忙解決的朋友~
--
1F:推 byone1 :加油,我是氧氣,你ez打得很不錯08/26 10:49
2F:→ sdsd65676 :3Q08/26 10:50
3F:→ sdsd65676 :雙排ING08/26 10:55
4F:→ kiki761119 :我主main ad 也可走top上08/26 11:34
5F:推 longkiss0618:加油 我是二氧化碳 你EZ不錯08/26 11:42
6F:推 Asty1e :加油 我是甲烷 你ez打的很不錯08/26 11:45
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.216.247.157
※ 文章網址: https://webptt.com/m.aspx?n=bbs/ASM/M.1516058571.A.939.html
7F:→ sdsd65676: 身家微薄,附上稅前200P給解決的大師! 01/16 07:24
8F:→ cocoaswifty: 把上面的if邏輯判斷放到loop()裡面 01/16 10:36
9F:推 BrianCashman: if內所有語法與函式參數皆不正確,請修正看看 01/16 11:57
11F:推 full0513: Setup裡不是都放基本設定而已嗎,那麽大串的判斷式應該 01/18 03:59
12F:→ full0513: 放在loop吧,才會重複執行 01/18 03:59