Hi guys, I'm new to this forum and Arduino. And This is my first post here
I have watched the video by Jeremy Blum on youtube to teach me how to use buttons and PMW on Arduino.
But I want to add new features to it.
the original code below written by Jeremy Blum will change the brightness of LED by pressing the buttons each time.( total is 5)
Switch4 Program (pwm)
Written by: Jeremy Blum
int switchPin = 8;
int ledPin = 11;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;
boolean debounce(boolean last)
boolean current = digitalRead(switchPin);
if (last != current)
current = digitalRead(switchPin);
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
ledLevel = ledLevel + 51;
lastButton = currentButton;
if (ledLevel > 255) ledLevel = 0;
If I want give a duty cycle to the LED when it's lighted,like the code below
delay(100); // Approximately 10% duty cycle @ 1KHz
how am I supposed to add those two code together?
For example, if I pressed the button first time and the LED will be on and flashing in a frequency and if I press again it will be brighter and flashing in the same frequency.
I'm really new to the C programming and arduino but willing to learn everything.
Thanks for any advice and help.