Wednesday, October 14, 2009

Shanna B Assignment #1

*/

int ledPin = 13; // LED connected to digital pin 13

int ledPin2 = 8; // LED connected to digital pin 8

int ledPin3 = 7; // LED connected to digital pin 7
const int analogPin = 0; // pin that the sensor is attached to
const int threshold = 100; // an arbitrary threshold level that's in the range of the analog input


// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

// initialize serial communications:
Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(50); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(50); // wait for a second

digitalWrite(ledPin2, HIGH); // set the LED on
delay(8); // wait for a second
digitalWrite(ledPin2, LOW); // set the LED off
delay(8); // wait for a second

digitalWrite(ledPin3, HIGH); // set the LED on
delay(200); // wait for a second
digitalWrite(ledPin3, LOW); // set the LED off
delay(200); // wait for a second

// read the value of the potentiometer:
int analogValue = analogRead(analogPin);

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
delay(250);
}
else {
digitalWrite(ledPin,LOW);
delay(20);
}

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin2, HIGH);
delay(375);
}
else {
digitalWrite(ledPin2,LOW);
delay(100);
}

// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin3, HIGH);
delay(20);
}
else {
digitalWrite(ledPin3,LOW);
delay(700);
}

// print the analog value:
Serial.println(analogValue, DEC);
}

No comments:

Post a Comment