231a-aj hwTest

From CSclasswiki
Jump to: navigation, search
/*
* Blink
*
* The basic Arduino example.  Turns on an LED on for one second,
* then off for one second, and so on...  We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
int brightPin = 8;
int LDR = 0;
int led1Pin = 7;
int led2Pin = 6;
int led3Pin = 5;
int led4Pin = 4;
int led5Pin = 3; 
int led6Pin = 2; 
                    //LDR input
int val = 0;                     //setup inital stored value

void setup()                    // run once, when the sketch starts
{
  Serial.begin(9600);
 pinMode(LDR, INPUT);
 pinMode(brightPin, OUTPUT); 
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  pinMode(led6Pin, OUTPUT);// sets the digital pin as output
  digitalWrite(brightPin, HIGH);
}

void loop2(){
 val = analogRead(LDR);
  Serial.println(val);
 delay(1000); 
}

void loop()                     // run over and over again
{
  
 val = analogRead(LDR);
 Serial.println(val);
 if (val == HIGH){
   digitalWrite(led1Pin, HIGH);
   digitalWrite(led2Pin, HIGH);
   digitalWrite(led3Pin, HIGH);
   digitalWrite(led4Pin, HIGH);
   digitalWrite(led5Pin, HIGH);
   digitalWrite(led6Pin, HIGH);
   digitalWrite(brightPin, HIGH);
 }   // sets the LED on                // waits for a second
 else{
 digitalWrite(led1Pin, LOW);
 digitalWrite(led2Pin, LOW);
 digitalWrite(led3Pin, LOW);
 digitalWrite(led4Pin, LOW);
 digitalWrite(led5Pin, LOW);
 digitalWrite(led6Pin, LOW);
 digitalWrite(brightPin, LOW);  // sets the LED off                 // waits for a second
 }
}