2012年11月27日 星期二

Week12,HW10

1.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:
  Serial.begin(9600);
  Serial.println("2222");
  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);   
  // turn the ledPin on
  int i=20;
  for(i=0;i<8;i++)
  {
  if(i=0)
  {
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  }
  else if(i==1)
  {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  }
    else if(i==2)
  {
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  }
    else if(i==3)
  {
  digitalWrite(10, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(13, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  }
    else if(i==4)
  {
  digitalWrite(9, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(13, LOW);
  digitalWrite(8, LOW);
  digitalWrite(7, LOW);
  }
    else if(i==5)
  {
  digitalWrite(8, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(13, LOW);
  digitalWrite(7, LOW);
  }
    else if(i==6)
  {
  digitalWrite(7, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
  digitalWrite(9, LOW);
  digitalWrite(8, LOW);
  digitalWrite(13, LOW);
  }
    else if(i==7)
  {
    i==0;
  }
  }
  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);                 
}

賴祺清的

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue =25;  // variable to store the value coming from the sensor
int s=7;
boolean turn =true;
void setup() {
  // declare the ledPin as an OUTPUT:
  for(int i =13;i>=7;i--){

  pinMode( i, OUTPUT);
}

 // pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
  // turn the ledPin on();

  Serial.println("Hello World!!");

         for(int i =13;i>=7;i--){
          if(s==i||s==i+1){
        digitalWrite(i, HIGH);
      }
        else digitalWrite(i, LOW);
          }
          // stop the program for <sensorValue> milliseconds:
        delay(sensorValue);        
     
      if(turn)s++;
      else s--;
       if(s==14||s==7)turn=!turn;
     
     
    }                

沒有留言:

張貼留言