Lab 2 part 3
This was a simple experiment using a pot to show changing lights from red–>yellow–>green–>yellow–>red
This is the code I wrote
int potPin = 0; // analog pin that pot attaches too “blue wire”
int potValue = 0; //value initial
int led3 = 3; // displays what the pot is doing
int led6 = 6;
int led9 = 9;
int led10 = 10;
int led11 = 11;
void setup(){
Serial.begin(9600);
}
void loop(){
/*
so I need potvalue/4 and divide by 7 to get the range
*/
potValue = analogRead(potPin); //read pot value
potValue = potValue/4;
if (potValue <= 42){ analogWrite(led3, 255); analogWrite(led6, 0); analogWrite(led9, 0); analogWrite(led10, 0); analogWrite(led11, 0); } else if((potValue > 42) && (potValue <= 84)){ analogWrite(led6, 255); analogWrite(led3, 0); analogWrite(led9, 0); analogWrite(led10, 0); analogWrite(led11, 0); } else if ((potValue > 84) && (potValue <= 126)){ analogWrite(led9, 255); analogWrite(led3, 0); analogWrite(led6, 0); analogWrite(led10, 0); analogWrite(led11, 0); } else if ((potValue > 126) && (potValue <= 168)){ analogWrite(led10, potValue); analogWrite(led3, 0); analogWrite(led6, 0); analogWrite(led9, 0); analogWrite(led11, 0); } else if ((potValue > 168) && (potValue <= 240)){
analogWrite(led11, 255);
analogWrite(led3, 0);
analogWrite(led6, 0);
analogWrite(led9, 0);
analogWrite(led10, 0);
}
//pwm led w/ pot value
Serial.println(potValue/4);//print value
delay(10);
}
Physcomp-Lab 2 part3 from Zeven Rodriguez on Vimeo.