Notifications
Clear all

Arduino memory  

  RSS

Raunak
(@raunaksaigal)
New Member
Joined: 7 months ago
Posts: 4
2020-04-11 4:48 pm  

Hi, this is my first post on the forum. I wanted to ask is there any way to make Arduino remember its previously done tasks? For example, I have 5 push buttons, and I press two of them. Then I want Arduino to recall which of the two buttons I had pressed.

thanking you and regards,

Raunak

P.S - Please guide me to properly use the forum if I have done anything wrong here as I am completely new to it. Once again thank you.


Quote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 353
2020-04-11 8:36 pm  
Posted by: @raunaksaigal

is there any way to make Arduino remember its previously done tasks? For example, I have 5 push buttons

Yes there is and one way is to generate an interrupt when a button is pressed and record this in a variable.  The uno only has 2 pins for interrupts, but other boards have more.   There is a way to make any pin to which a button is attached generated a single interrupt, that then finds outs which pin/button was pressed and records it.   I gave an example of this a while back to some other post.  The link is #newb Could I simplify my code?   


ReplyQuote
Raunak
(@raunaksaigal)
New Member
Joined: 7 months ago
Posts: 4
2020-04-12 6:15 pm  

I did not get it quite really there. Could you give me an example with three buttons? It would be more helpful 🙂 (Actually I am a newbie to arduino...just a high school student).

Thank you for ur help and cooperation

Regards,

Raunak


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 353
2020-04-12 10:32 pm  

Yes, sorry, the example I linked to was not so simple.  As you are starting out then to start with keep it simple.  I suggest you start with just one push button.  Here is a link to a tutorial on getting one push button to switch on an LED.

https://www.arduino.cc/en/tutorial/pushbutton  

So, once you see how to take an action (LED on or off) on a button push, then your next step is to do something else like store a value into a variable when the button is pushed (and maybe make an LED go on and off at the same time).  And what to store?  Do you want to increment a counter of the number of times its pushed, or store the time of day it was pushed?  Compose your code in little steps with just one push button, then repeat for more buttons until you run out of pins to attach your button to.   But I will also observe that before playing with Arduino's its worth your while to get hold of a beginners book and work your way through the examples.  Here is a link to a freely downloadable book.  

https://hackspace.raspberrypi.org/books/arduino


Raunak liked
ReplyQuote
Raunak
(@raunaksaigal)
New Member
Joined: 7 months ago
Posts: 4
2020-04-22 3:36 pm  

@byron thanks...it has helped me a lot 😀 😊 .

with regards

Raunak


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2020-04-29 4:28 pm  

@byron

Posted by: @raunaksaigal
Posted by: @raunaksaigal

is there any way to make Arduino remember its previously done tasks? For example, I have 5 push buttons

Yes there is and one way is to generate an interrupt when a button is pressed and record this in a variable.

Yes, you can use an interrupt, but that's not really what interrupts are supposed to be used for... as you could record the button presses in variables even without an interrupt anyway, which for a newbie is probably an easier route to take.


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 353
2020-04-29 5:20 pm  
Posted by: @frogandtoad

Yes, you can use an interrupt, but that's not really what interrupts are supposed to be used for.

In the context in which the question was raised I agree I initially overcomplicated the answer, and subsequently pointed the questioner to a polling solution.  However interrupts on a button press are indeed a target for using an interrupt in the context of a hardware device requiring attention.  Interrupts are frequently underused and are a valuable way to send signals to your code.  All manner of interaction with physical devices use interrupts as does software such as serial communications and the likes of mqtt.  Interrupts are there to be used in our small board microprocessors and SBC's and a long as used correctly there's no reason not to make full use of them in whatever context the user desires.


ReplyQuote
frogandtoad
(@frogandtoad)
Reputable Member
Joined: 1 year ago
Posts: 490
2020-04-30 10:27 am  

@byron

Posted by: @byron

However interrupts on a button press are indeed a target for using an interrupt in the context of a hardware device requiring attention.

Indeed, I agree with this statement, but too many people abuse interrupts for simple tasks that could easily be achieved without them.

Posted by: @byron

Interrupts are frequently underused

From what I see, that is a very debatable topic 🙂

Posted by: @byron

 Interrupts are there to be used in our small board microprocessors and SBC's and a long as used correctly there's no reason not to make full use of them in whatever context the user desires.

Correctly being the key term... just like interrupts (IRQ's) in your computer, they should only be implemented where algorithms in heavy loops need to be er "interrupted" to allow another command/task to grab a time slice of the CPU and take precedence for an unnatural event (for example, interrupting a heavy file search using a cancel button)... unless your program operates under such constraints or conditions, then an interrupt is not necessarily a reason to use one.


ReplyQuote
byron
(@byron)
Reputable Member
Joined: 1 year ago
Posts: 353
2020-04-30 11:10 am  

@frogandtoad

Indeed, indeed. Used correctly of course.  Well we seem to be mostly in agreement then. 😀  As for whether interrupts are underused I say high, you say low, thats life 😋 


ReplyQuote