Our Code:
int led = 9;// the PWM pin the LED is attached to
int knob = 0;
int brightness = 0;// how bright the LED is
//int fadeAmount = 5; // how many points to fade the LED by
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(A0, INPUT);
}
void loop() {
analogWrite(led, 0);
knob = analogRead(A0);
if(knob < 400) {
led = 11; //green
Serial.print("green light ");
}
else if (knob > 400 && knob < 700) {
led = 10; // yellow
Serial.print("yellow light ");
}
else { //brightest
led = 9; //red
Serial.print("red light ");
}
Serial.print("knob is ");
Serial.println(knob);
brightness = map(knob,0,845,0,255);
Serial.print("brightness is ");
Serial.println(brightness);
//brightness = brightness + fadeAmount;
//if (brightness == 0 || brightness == 255) {
//fadeAmount = -fadeAmount ;
//}
analogWrite(led,brightness);
delay(200);
}
No comments:
Post a Comment