This is my Arduino Uno circuit and we have given the problem to blink the LED by pressing the push button .
~ press one push button blink or on 3 LED (No matter first 3 or in even odd pattern )
~ press next push button blink next 3 or (even odd pattern)
The code we needed will be in c++ and I'm very poor in this programming language.
So can anyone help me to solve the problem.. PLEASE............
Why do you expecting that someone will do your homework?
Did you try to code yourself? If so - please show your efforts.
I want to check that "is still humanity alive or dead". ![]()
Who have you that?
What was the previous problem you were given, and how did your solution to that look?
You can't be expected to start from nowhere, someone must think she is teaching you, what have you learned so far?
No one here is just going to dash off you homework for you, but we will help you get your best efforts to compile and run correctly.'
a7
You start here. Then using code tags you post your code. Then you describe in detail exactly how you figure your code and your circuit should work. Nobody here is going to do any school assignments for you.
Ron
Start by using the example codes provided by the IDE. There is code for reading buttons and code for blinking LEDs.
A good test would be to see whether they can solve their own problems. What are the strange T1, T2, T3 thingies on your Fritzling?
Did you design the circuit? The push buttons are wired incorrectly. They will be high impedance and "float" around when the buttons are not pushed.
Have you looked at the switch/LED tutorials on this site? The example sketches that ship with the IDE? Don't you think that simple example code might help you along?
Do you have hardware, or is this just a simulation?
One problem I see is using GPIO_NUM_0 and GPIO_NUM1 as outputs. Can the OP figure out why those pins is not a wise choice to use? Hint, search on the internet for the answer.
What is your programming background?
One button basics: https://arduinointro.com/articles/projects/using-simple-pushbutton-switches-to-light-up-leds
More examples: https://docs.arduino.cc/built-in-examples/
You have your basic requirement stated.
Restate it to remove ambiguity:
- Press button_0 to blink LEDs #0, #1, and #2
- Press button_1 to blink LEDs #3, #4, and #5
Think about LEDs blinking, as it is a common between both buttons.
To be active, a LED must be connected to an output pin which is coded in the setup() section of the code. The output pin will then need to be alternately switched between "On" and "Off" states to allow current to be switched and thus make the LED light and extinguish.
Note: setup() is a one-time thing, so setting up input/output pins must all be completed in this part of the program. As you need to monitor your button(s), they are configured to input pins and these are also coded in setup(). The basic example shows this, repeat for more buttons & more LEDs.
Note: loop() does exactly that, it just repeat whatever is underneath. So, it would seem appropriate to read our button(s) early in this process and make a decision on the LEDs afterward. Decisions can be handled multiple ways, but if() is a very common approach.
As we really wish to control 6 total LEDs, we must define 6 total Output pins in setup(). Then in loop(), we can code 3 to be "On" while 3 are "Off" ... "On" & "Off" are just programming-speak for controlling the current on the Output pin(s).
Because this is a "beginners'" problem, I assume that the delay(n) Arduino function can be used to control the blinking rate, a value of delay(500) means wait for half-a-second. In the future, you may be asked to code more efficiently and avoid delay().
I recommend starting your coding by using the first tutorial and learning the program structure for using a button & LED.
An Internet search will provide more examples to assist you in enabling more LEDs and in controlling "if" logic within the loop() to selectively manage groups of LEDs.
When you construct a query for the search-engine, try to make it simple enough to catch what you are interested in seeing but not so complex that you miss relevant articles ![]()
Hello thakurb
Try, check and modify this sketch to the project requ.
struct BUTTONBLINK
{
const int ButtonPin;
const int LedPins[3];
unsigned long stamp;
const unsigned long duration;
};
BUTTONBLINK buttonBlinks[]
{
{A0, 2, 3, 4, 0, 1000},
{A1, 5, 6, 7, 0, 777},
};
void setup()
{
for (auto buttonBlink : buttonBlinks)
{
pinMode(buttonBlink.ButtonPin, INPUT_PULLUP);
for (auto LedPin : buttonBlink.LedPins)
{
pinMode(LedPin, OUTPUT);
digitalWrite(LedPin, HIGH);
delay(1000);
digitalWrite(LedPin, LOW);
}
}
}
void loop()
{
unsigned long currentMillis = millis();
for (auto &buttonBlink : buttonBlinks)
{
if (currentMillis - buttonBlink.stamp >= buttonBlink.duration && (digitalRead(buttonBlink.ButtonPin) ? LOW : HIGH))
{
buttonBlink.stamp = currentMillis;
for (auto &LedPin : buttonBlink.LedPins) digitalWrite(LedPin, digitalRead(LedPin) ? LOW : HIGH);
}
}
}
Have a nice day and enjoy coding in C++.
I think your buttons are miswired. You need a pull-up or pull-down resistor on the I/O pin side of the button. You have a resistor between the button and +5V but nothing on the I/O pin side.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
