I am very fresh in this area and am still have a lot to learn.
I followed a video tutorial and decided to make some improvement. Initially it was an LED with a switch, the LED get brighter as the switch being pressed, then back to off after the value reached past 255. I tried to make changed to this working solution. The change is that the light will BLINK brighter as the switch being pressed. It will never get brighter and needed multiple presses to get a signal (I used serial write to test this).
Please ,please help me...
Please find below is my code:
What should I do if not using delay to blink the LED?
In your code, if ledOn is true then two 500 millisecond delays will be triggered and during each of them the Arduino will do nothing. So, for one second it cannot read your switch. One second may not sound like much but it will seriously affect how responsive your system is to inputs.
You need to consider using millis() as in the BlinkWithoutDelay example in the IDE so that your program can read a switch whilst blinking the LED.