Uncategorized

Active today
Viewed 21 times

How to use “State Diagrams” to describe the states of LEDs, Buttons, etc of a Rpi game machine？

I am trying to describe the states of all my units connected to the Raspberry Pi. I have several buttons, magnets, reed switches, LEDs, and other. This is a game and it has few phases. I want to describe states of each element for each phase and conditions to pass from one phase to another. I tried to use a state diagram, but there no states for elements. May be somebody has an example or the name of this diagram?

• Your question is unclear to me, but AFAIK, what you seem to be describing is in fact a state diagram. There are several “types” of state diagrams with different characteristics – perhaps that’s what you’re after? Try this Wikipedia article on state diagrams as a starter. – Seamus 6 hours ago
• Hi Dzam, welcome and nice to meet you. Ah let me see. You gaming system is a bit completed. Now let me summarize. (1) Your game system has physical devices such as LED, button, magnet, reed etc. (2) You system has “phases” such as (a) game setup, (b) game playing, (c) game over, (3) Each phase has sequential/concurrent “states” such as the following: (4) State x: (i) all LED on, (ii) all button not pushed, (iii), … (5) State y: (i) button 2 pushed, (ii) reed on, (iii) magnet demagnetized, … You might like to comment or make counter suggestion on how to describe it. / continue, .. – tlfong01 5 hours ago
• You might to wiki for a rough idea: (1) “State Diagram – Wikipedia“：en.wikipedia.org/wiki/State_diagram, (2) “UML State Machine – Wikipedia”：en.wikipedia.org/wiki/UML_state_machine. I like the UML wiki better. UML explains “actions” “trigger” “events”, “behaviour” “protocol” rather than state “transitions” It is good to use a pocket calculator example states: (a) switch on calculator, (b) push button (action) trigger events (LCD display digits), (c) protocols eg. to add two numbers, (i) “x > + > y > =” or (ii) “= > x > y > +”. State stuff is a hard. Go slow. Cheers. – tlfong01 4 hours ago
• And you don’t need newbie scary state diagrams with labelled circles and arrows. Those diagrams are very hard to draw nicely. For newbies toy projects, a flowchart can do as well: (1) Flowchart I2C event triggered state trnsisition: imgur.com/gallery/ja4GlM0. Actually even flowchart type state diagrams are also hard to draw. I am usually lazy and just draw timed decision charts. Please let me know if you wish to see my example of decision tables. Feel free to ask me other state diagrams questions newbies are too afraid to ask. Happy gaming. Cheers. – tlfong01 3 hours ago
• References: (1) “Digital 16bit Serial Output Type Ambient Light Sensor IC – RoHM Semi”:mouser.com/datasheet/2/348/bh1750fvi-e-186247.pdf (2) “Using the BH1750FVI I2C Digital Light Sensor – matt, RpiSpy 2015mar31”: raspberrypi-spy.co.uk/2015/03/…, (3) Using BH-1750 Light Sensor Problem raspberrypi.stackexchange.com/questions/112485/…. Cheers. – tlfong01 3 hours ago
• A pocket calculator is a state machine: imgur.com/gallery/8DjmLBc. – tlfong01 1 hour ago
• It is not clear why you say the following: “I tried to use a state diagram, but there [are] no states for elements, …”. I think each of your “elements” has states, logical or analogue states. For example LED may be in ON or OFF state, Reed switch ON or OFF state. Magnet may be in ENERGIZED or NON-ENGERIZED state. Sometimes it is confusing to differentiate between “state”, “event”, or “action”. For example, push button may be in “pushed” or “released state” state, but you can also say pushing or releasing are actions or events which caused transitions of states. / to continue, … – tlfong01 6 mins ago
• For example, a pushing button action or event may cause a LED’s state’s transition from OFF to ON. I know it is vague or abstract. Perhaps I can think hard and give a real life example, say, using just LEDs and buttons, to make the story simple. Another complication is that implementing games usually needs “event driven” programming, using LUA for example, or multprocessing programmng using python’s multi-threading or multi_processing modules. By the way, python GpioZero is also multithreading and so can be used to implement concurrent LED and buttons. – tlfong01 just now   Edit

Categories: Uncategorized

This site uses Akismet to reduce spam. Learn how your comment data is processed.