int ledPin = 6;
int buttonPin = 3;
int buttonPressed = 0;
int bright = 0;
int dir = 1;
int potPin = A0;
int newValue = 0;
int potValue = 0;
void setup(){
Serial.begin (9600);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
pinMode (potPin, INPUT);
digitalWrite (buttonPin, HIGH);
}
void loop (){
buttonPressed = digitalRead (buttonPin);
Serial.println (buttonPressed);
bright = bright + dir;
delay (100);
potValue = analogRead(potPin);
newValue = map(potValue, 0, 1023, 0, 200);
//Serial.print (potValue);
Serial.println (newValue);
if (buttonPressed == 0){
digitalWrite(ledPin, HIGH);
dir += -1;
}
else{
analogWrite (ledPin, newValue);
bright = newValue;
}
analogWrite(ledPin, bright);
if (bright >= 255){
bright = 0;
}
}


