Wednesday, October 7, 2009

Aysha Homework: 10/7/09

Exercise 1




int ledPin = 11; //sets led pin to 11
int potPin = 0; //sets pot pin to andalog 0
int outValue = 0; //value sent to pin
int potValue = 0; //value given from pot



void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //sets lefPin to output
}

void loop(){

potValue = analogRead(potPin); //reads the value of the pot and sets it
outValue = potValue/4; //sets outValue to potValue divided by 4
analogWrite(ledPin, outValue); //sends the value of pot to led
Serial.println(outValue); //prints the calue being sent to led
delay(1);
}





Exercise 2



/*use an array to light up a series of LED, over a series of time.
Use for loops as the counters for your timer. Use your switch or
variable resistor to change this sequence of lighting the LED's to
light in the opposite direction upon input from the switch/variable
resistor*/

int pinA = 3;
int pinB = 4;
int pinC = 5;

int buttonPin = 2;
int buttonState = 0;

int testLED = 13;

int arrayLED[3] = {pinA, pinB, pinC}; //array for LED pins


void setup(){
//use array to set up pins as output

for(int i = 0; i < buttonstate =" digitalRead(buttonPin);" buttonstate ="="" x =" 0;" buttonstate ="="" y =" 5;"> 5; y--){
digitalWrite(arrayLED[y], HIGH);
delay(300);
digitalWrite(arrayLED[y],LOW);
delay(300);
}
}
}







Exercise 3

No comments:

Post a Comment