File: trafficLightDemo.py

package info (click to toggle)
pyparsing 3.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,928 kB
  • sloc: python: 25,633; ansic: 422; makefile: 22
file content (26 lines) | stat: -rw-r--r-- 550 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#
# trafficLightDemo.py
#
# Example of a simple state machine modeling the state of a traffic light
#

import statemachine
import trafficlightstate


class TrafficLight(trafficlightstate.TrafficLightStateMixin):
    def __init__(self):
        self.initialize_state(trafficlightstate.Red)

    def change(self):
        self._state = self._state.next_state()


light = TrafficLight()
for i in range(10):
    print("{} {}".format(light, ("STOP", "GO")[light.cars_can_go]))
    light.crossing_signal()
    light.delay()
    print()

    light.change()