Author Options:

How to chose between auto run or manual control of blink and fade of an LED? Answered

dear sir,

my name is ahmed darwish

i'm a teacher

i'd like to make a project for students to show them the capabilities of the UNO

my project is as follows first board: LED

in this board i have several mode:

mode one chosen by PB1 to blink of the LED automatically

mode two chosen by PB2 to PWM of the an LED automatically

mode three chosen by PB3 to switch on and off the LED manually by PB

mode four chosen by PB4 to control the delay of blink of the LED manually by variable resistor

mode five chosen by PB5 to control the PWM value of the LED manually by variable resistor

I though i can assign an integer that takes the number assigned to each PB and upon the value of that integer the loop shall perform a certain routine and ignores the others.

can you help me with that please? have many thanks.

you are welcome to contact me directly on my mail: e_ahmeddarwish@hotmail.com or my cell phone: 0096551105252



1 year ago

It might not be that simple.
Check the Arduino Playground for some examples.

I would start with one routine just for the buttons and the potentiometer.
In there you assign variables according to the input.
The second routine does the actual work.
Here you use the variables to define the output - the LED.

In the Playground you should find examples on how to run two or more task at the same time using interrupts orby including other code for example.
The later works by just calling the code by "include codename.h" or whatever you specify for it.
For PWM control of a LED you will find plenty of usable examples from simple to complex.

Doing it all in just one code block is certainly possible too.
Pretty much similar to the above, assing the intup to variables and after that have the rest deal with output.
Key is not to make it too long and to include checks to eliminate someone pressing more than one button at once for example.