API
- class tl.TrafficLight
Bases:
objectControl Raspberry Pi’s GPIO pins to operate traffic lights.
- _GPIO_RED
GPIO pin number for the red light.
- Type:
int
- _GPIO_GREEN
GPIO pin number for the green light.
- Type:
int
- _HIGH_OFF
High level state indicating light is off.
- Type:
int
- _LOW_ON
Low level state indicating light is on.
- Type:
int
- all_off()
Turn off both the red and green lights.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- all_on()
Turn on both the red and green lights.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- cleanup()
Clean up GPIO settings to ensure all resources are released.
- Returns:
True if GPIO cleanup is successful; otherwise, False.
- Return type:
bool
- green_off()
Turn off the green light.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- green_on()
Turn on the green light.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- green_on_only()
Turn on the green light only, ensuring the red light is off.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- red_off()
Turn off the red light.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- red_on()
Turn on the red light.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool
- red_on_only()
Turn on the red light only, ensuring the green light is off.
- Returns:
True if the operation is successful; otherwise, False.
- Return type:
bool