int led = 9;
int button = 8;
int buttonState =0;
int brightness = 0;
int brightup = 2;
int duty = 50;
int nduty = map(duty, 0, 100, 0, 255);
void setup ()
{
TCCR2B &= ~ _BV (CS22); // cancel pre-scaler of 64
TCCR2B |= _BV (CS20);// no pre-scaler
analogWrite (9, nduty);
//analogWrite (10, 200); // 78.4 % duty cycle
} // end of setup
void loop () { analogWrite(led, brightness);
buttonState = digitalRead(button);
if ( buttonState == HIGH ) {
brightness = brightness + brightup;
}
if ( brightness == 128 ) {
brightness = 0;
}
delay(30);
}
Please also tell me how to use code tags