2012年11月27日 星期二

Week12,HW9

作業:

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() {
  Serial.begin(9600);
  // declare the ledPin as an OUTPUT:
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
   Serial.println(sensorValue);
  // turn the ledPin on
  digitalWrite(13, HIGH);
  delay(50);
  digitalWrite(12, HIGH);
  delay(100);
  digitalWrite(11, HIGH);
   delay(150);
  digitalWrite(10, HIGH);
     delay(200);
  digitalWrite(9, HIGH);
   delay(250);
  digitalWrite(8, HIGH);
   delay(300);
  digitalWrite(7, HIGH);
   delay(350);
  // stop the program for <sensorValue> milliseconds:
  delay(sensorValue);        
  // turn the ledPin off:      
  digitalWrite(7, LOW);
  delay(50);
  digitalWrite(8, LOW);
  delay(100);
  digitalWrite(9, LOW);
  delay(150);
  digitalWrite(10, LOW);
  delay(200);
  digitalWrite(11, LOW);
  delay(250);
  digitalWrite(12, LOW);
  delay(300);
  digitalWrite(13, LOW);
  delay(350);
  // stop the program for for <sensorValue> milliseconds:
  delay(sensorValue);                
}

影片:

沒有留言:

張貼留言