Arduino Forum

Topics => Interactive Art => Topic started by: gindhartmakes on Mar 26, 2019, 12:41 am

Title: button press within a given time-frame determining an action at a specific time
Post by: gindhartmakes on Mar 26, 2019, 12:41 am
Okay so this is pretty weird, but I'd really appreciate some help...

I am in the process of making a chair for my senior thesis that, well... lays eggs (with baby chairs in them). I have a general idea of the logic behind the code, I've just never tried to use a button switch in this way. The eggs will be 'fertilized' if someone sits in the chair within a 24 hour period. If someone sits in the chair, an egg with a small chair in it will be laid the next day. If nobody sits in the chair, the eggs will be unfertilized and an empty egg will be laid. I am just planning on putting a momentary button switch in the seat cushion so I will be able to keep track of whether or not someone sat in the chair, I just don't know how to then use that information to determine which servo is activated to lay either a fertilized or unfertilized egg.

basically, I am trying to accomplish this:

if a button is pushed 1 or more times between 2 pm one day, and 2 pm the next day, then at 2 pm, activate the motor that causes the fertilized egg to fall out.

if the button is not pushed during that time frame, activate the other motor to lay an unfertilized egg.

after an egg is laid, begin reading to see if the button is pressed within the next 24 hours.



Thanks so much, any help would be greatly appreciated!

Title: Re: button press within a given time-frame determining an action at a specific time
Post by: slipstick on Mar 26, 2019, 10:04 am
So every day at 2pm an action happens. It could be action A or action B depending on if a button was ever pushed in the previous 24 hours.

So you have an RTC (Real Time Clock). From there it sounds pretty straightforward. Have a flag which is set if the button is pushed. At 2pm perform action A or action B depending on if the flag is set or not. Then immediately unset the flag and start waiting for possible button pushes until 2pm comes round again.

There are code examples in the IDE that cover recognising a button push, moving a servo etc. Which part is causing you problems (apart from the physical/mechanical aspect of making baby chair eggs etc)?

Steve
Title: Re: button press within a given time-frame determining an action at a specific time
Post by: gindhartmakes on Mar 26, 2019, 07:34 pm
So every day at 2pm an action happens. It could be action A or action B depending on if a button was ever pushed in the previous 24 hours.

So you have an RTC (Real Time Clock). From there it sounds pretty straightforward. Have a flag which is set if the button is pushed. At 2pm perform action A or action B depending on if the flag is set or not. Then immediately unset the flag and start waiting for possible button pushes until 2pm comes round again.

There are code examples in the IDE that cover recognising a button push, moving a servo etc. Which part is causing you problems (apart from the physical/mechanical aspect of making baby chair eggs etc)?

Steve
Thanks for the reply! I have most of the mechanics figured out, was just having a hard time figuring out how to get the button to influence the servos. I know how to make a button do something, or do something with a delay, I just couldn't wrap my head around the code for this particular situation. I'll look into the Real Time Clocks and play around. It really isn't that complicated, I've just been overthinking it and my brain is fried. Thanks again!