Russell Gillie

Greenhorn
+ Follow
since Nov 26, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
1
Forums and Threads

Recent posts by Russell Gillie

Paul,
The buttons are codes received by an Arduino from a tv remote.  A finite state machine will do the trick, but it's not just push remote button 1 --do this.  It's almost like locking out previous and next states until conditions are met --but it's all about the remote button pushes.

Tim was getting what I was saying and I just hoped he could provide an example code of what he was talking about:

My normal structure is that the loop() function has a state switch statement in it (and I use enums as states). When I want to change state, I call a newState() function, passing the next desired state as its argument. The newState() function is where I usually call action functions relating to leaving the old state and entering the new one. So actually, a green-to-yellow operation in newState would see that the new state was no longer green, but since the prior state was green, it would turn off the green light. I'd then set the current state to the new state value, and a switch statement for the new state would turn on the yellow light.

So in total, I'd have 3 switch statements. One in the main loop, where I monitor for events and, depending on what state I'm currently in, possible switch to a new state. Then in the newState method, there'd be a switch to handle leaving the old event, a statement changing the current state value, and a switch to fire actions related to the new state.

3 days ago
Hi Tim,
I compose music in my sleep.  But I'm not the sharpest knife in the drawer when it comes to coding.  I wonder if you could point me to an example code of what you are describing.
3 days ago
Hello,

I'd like to preface this question with with what is working for me and to say I have been researching for a month
on how to solve my problem.  Any code I come up with isn't even close.  It just ends up being a convoluted mess.

I'm just looking for a little direction is all, in the form of pseudo code.

I'm working on a model of a spaceship that does various movements and lights and sounds based on ir remote button pushes.

I have set up a hypothetical problem so I can learn how to control several things with Arduino and it's code.

I have no issues with the hardware side.  I'm a very slow learner when it comes to code.

I figured out how to control 3 LED's with switch/case.  Pretty easy.  Each led turns of and on with three different remote buttons "independently".

Here's the code:




Works great.
 I can't for the life of me figure out the following problem:
 Red led is turned on/ off by button 1.
 Only when button one is "on", will control go to button two which turns yellow led on/off.
 Only when button two is "on", will control be allowed for button 3 to turn green led on/off.

Only when green is off will yellow be allowed to turn off/on.
Only when yellow is off will red be allowed to turn off/on.

The attached image shows three flow charts that kind of get my problem across but doesn't help me code correctly.
Each chart is saying the same thing in a different way.

I don't have any code that isn't just garbage.  I can't even post it.

If anyone can help me along solving this hypothetical problem, it would go a long way to help me with the actual project.

1 week ago