擺放位置 | ||||
名稱 | 宣告 | setup | loop | 說明 |
輸出控制 | int led = 3; | pinMode(led, OUTPUT); | digitalWrite(led, HIGH); digitalWrite(led, LOW); |
輸出0或1 |
輸出PWM (亮度調整) |
int led = 3; int brightness = 0; |
pinMode(led, OUTPUT); | brightness=100; //0~255 analogWrite(led, brightness); |
輸出(0~255)/255的不同的比例 0.39%~100% |
輸入控制 | int pushButton = 3; | pinMode(pushButton, INPUT); | int buttonState = digitalRead(pushButton); | 讀取按鈕狀態為0或1 |
輸入類比訊號 | int sensorPin = A0; int sensorValue=0; float voltage=0; |
sensorValue = analogRead(sensorPin); float voltage = sensorValue * (5.0 / 1023.0); |
訊號數值為0~1023 | |
資料傳輸 | int myValue; | Serial.begin(9600); | myValue=20; Serial.print("myValue="); Serial.println(myValue); |
透過COM Port顯示序列資料 |
延遲ms | delay(1);// 1ms | |||
延遲us | delayMicroseconds(1);//1us=0.001ms |
全站熱搜
留言列表