2018年12月13日 星期四

week14



---------

void setup()
{
    pinMode(13,OUTPUT); //設定Led為output
}

void loop()
{
    int value=analogRead(A0);
    digitalWrite(13,HIGH); //LED 閃爍
    delay(value);
    digitalWrite(13,LOW); 
    delay(value);
}

---------

程式如下:
(未來可以用在控制滑鼠的鼠標位置)

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);
}


沒有留言:

張貼留言