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
First, I think it's very unwise to put your email and mobile number here. I doubt if anyone will use them to help you, preferring to help here in the forum, so rather edit them out.
You could easily have a variable called say theMode, and as you say set it to a certain value based on the button that's pressed, something like:
if (digitalRead(PB1)==LOW) theMode=1; //assuming an input_pullup and button to ground
if (digitalRead(PB2)==LOW) theMode=2;
Then use the value of theMode as your key into a switch...case.
You cannot use the Pxn pin notations with Arduino's standard IO functions. You need to use Arduino pin numbers with Arduino IO functions. For introducing students to Arduino, I would recommend that you use the Arduino pin numbers. This will be much more beginner friendly and allow the students to use the pin numbers as written on the silkscreen of the Uno. Once they are at a more advanced stage, you can teach them about doing direct port manipulation instead of using the Arduino functions if you wish.