Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a state machine #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Use a state machine #1

wants to merge 1 commit into from

Conversation

rkuris
Copy link

@rkuris rkuris commented Feb 11, 2022

Noticed a few bugs:

  • Pressing ctrl-C didn't stop the program right away since it only
    checked for interrupts after completing the loop
  • The LEDs start off, so turning them off at startup isn't strictly
    necessary
  • .gitignore wasn't ignoring all the right stuff, switched to
    gitignore.io

Ended out unrolling this into a state machine, mostly just to practice
some rust.

Example run, with debugging enabled:

pi@raspberrypi:~/rust/rustpitrafficlights $ RUST_LOG=debug cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Running target/debug/rustpitrafficlights
[2022-02-11T19:13:49Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
[2022-02-11T19:13:52Z DEBUG rustpitrafficlights] RedAmber: red: true, amber: true, green: false
[2022-02-11T19:13:53Z DEBUG rustpitrafficlights] Green: red: false, amber: false, green: true
[2022-02-11T19:13:58Z DEBUG rustpitrafficlights] Amber: red: false, amber: true, green: false
[2022-02-11T19:14:00Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
[2022-02-11T19:14:03Z DEBUG rustpitrafficlights] RedAmber: red: true, amber: true, green: false
[2022-02-11T19:14:04Z DEBUG rustpitrafficlights] Green: red: false, amber: false, green: true
[2022-02-11T19:14:09Z DEBUG rustpitrafficlights] Amber: red: false, amber: true, green: false
[2022-02-11T19:14:11Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
^C[2022-02-11T19:14:14Z DEBUG rustpitrafficlights] All LEDs off

Noticed a few bugs:
 - Pressing ctrl-C didn't stop the program right away since it only
   checked for interrupts after completing the loop
 - The LEDs start off, so turning them off at startup isn't strictly
   necessary
 - .gitignore wasn't ignoring all the right stuff, switched to
   gitignore.io

Ended out unrolling this into a state machine, mostly just to practice
some rust.

Example run, with debugging enabled:

pi@raspberrypi:~/rust/rustpitrafficlights $ RUST_LOG=debug cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/rustpitrafficlights`
[2022-02-11T19:13:49Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
[2022-02-11T19:13:52Z DEBUG rustpitrafficlights] RedAmber: red: true, amber: true, green: false
[2022-02-11T19:13:53Z DEBUG rustpitrafficlights] Green: red: false, amber: false, green: true
[2022-02-11T19:13:58Z DEBUG rustpitrafficlights] Amber: red: false, amber: true, green: false
[2022-02-11T19:14:00Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
[2022-02-11T19:14:03Z DEBUG rustpitrafficlights] RedAmber: red: true, amber: true, green: false
[2022-02-11T19:14:04Z DEBUG rustpitrafficlights] Green: red: false, amber: false, green: true
[2022-02-11T19:14:09Z DEBUG rustpitrafficlights] Amber: red: false, amber: true, green: false
[2022-02-11T19:14:11Z DEBUG rustpitrafficlights] Red: red: true, amber: false, green: false
^C[2022-02-11T19:14:14Z DEBUG rustpitrafficlights] All LEDs off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant