Arduino 學習筆記#8 宣告(取綽號)

在Arduino中,可將重複出現的程式碼取個綽號,如同設計軟體Sketch的symbol或網頁前端的class。

宣告語法(獨立於setup()和loop()之外):
int led = 7;
之後只要將led套用在7出現的位子即可(若取的名字從黑色變成其他顏色,則代表用到Arduino的保留字—代表內建的指令或功能)

範例(專案#6閃爍LED):
int led = 7
void setup(){
    pinMode(pin, OUTPUT);
}
void setup(){
    digitalWrite(pin, HIGH);
    delay(1000);
    digitalWrite(pin, LOW);
    delay(1000);
}

學習影片:
https://www.youtube.com/watch?v=8lfrjiA4nAg

Comments

Popular posts from this blog

Arduino 學習筆記#5 上拉電阻

Arduino 學習筆記#11 每按一次按鈕,切換一次燈的暗亮

Arduino 學習筆記#3 讀取接腳的狀態