2018年12月13日 星期四

Week14_黃惠嘉

🔺範例
檔案➪範例➪0.3AnalogAnalogIntput


範例+MAKER UNO+旋鈕
接法如下
http://www.arduino.cc/en/Tutorial/AnalogInput



程式碼

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);
}



LED燈會隨著旋鈕變大變小

沒有留言:

張貼留言