Help me #412
ludoiphone
started this conversation in
General
Help me
#412
Replies: 1 comment
-
I don't know much about low-level APIs or how to use raspberry pi to control the hardware GPIO... Without entering the details, a high-level approach could be to simply wrap the GPIO interface into the callbacks available: import RPi.GPIO as GPIO
from statemachine import StateMachine, State, Transition
GPIO.setmode(GPIO.BCM)
AC_POWER_PIN = 17 # Example GPIO to turn on/off the air conditioner
# Configure the GPIO
GPIO.setup(AC_POWER_PIN, GPIO.OUT)
def gpio_turn_ac_on():
GPIO.output(AC_POWER_PIN, GPIO.HIGH)
print("GPIO: On.")
def gpio_turn_ac_off():
GPIO.output(AC_POWER_PIN, GPIO.LOW)
print("GPIO: Off.")
# Classe da Máquina de Estados
class AirConditionerStateMachine(StateMachine):
off = State(initial=True)
on = State()
turn_on = off.to(on, on=gpio_turn_ac_on)
turn_off = on.to(off, on=gpio_turn_ac_off)
if __name__ == "__main__":
ac = AirConditionerStateMachine()
try:
print(f"Current state: {ac.current_state.name}")
ac.turn_on()
print(f"Current state: {ac.current_state.name}")
ac.turn_off()
print(f"current state: {ac.current_state.name}")
finally:
GPIO.cleanup() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am French: so I translate with Google.
your state machine interests me
I'm new to the world of python programming for my raspberrypi (4), and I would like to create a state machine for my reversible air conditioning (I created the code in C for arduino). I would like to have an example of a state machine that manages gpios (input, output), end to the extent possible and if you have a bit of time to give me. I learn quite quickly. the link of my machine has state C:
https://wokwi.com/projects/383798765269867521
Beta Was this translation helpful? Give feedback.
All reactions