# ---------------------------------------------------------------------
# METHOD : 1
# INITIALIZE the pins.
#
# set_all_pins() : you can use function :
# set_all_pins(north_yellow_pin=0,north_green_pin=0,north_red_pin=0,
# east_yellow_pin=0,east_green_pin=0,east_red_pin=0,
# west_yellow_pin=0,west_green_pin=0,west_red_pin=0,
# south_yellow_pin=0,south_green_pin=0,south_red_pin=0
# )
# Here, set_all_pins is function name, the arguments passed in the set_all_pins are pin numbers.
#
# Firts three pins are for North traffic Light:
# north_yellow_pin=0
# north_green_pin=0
# north_red_pin=0
# Firts three pins are for East traffic Light:
# east_yellow_pin=0
# east_green_pin=0
# east_red_pin=0
# First three pins are for West traffic Light:
# west_yellow_pin=0
# west_green_pin=0
# west_red_pin=0
# First three pins are for South traffic Light:
# south_yellow_pin=0
# south_green_pin=0
# south_red_pin=0
#
# ----------NOTE : BY DEFAULT THE PINS ARE SET TO ZERO-----------------------------
#
# METHOD : 2
# You can INITIALIZE the pins by calling the different pins directly
#
# FOR NORTH PIN INITIALIZATION use this function :
# set_north_pin(north_yellow_pin=0,north_green_pin=0,north_red_pin=0);
#
# FOR EASR PIN INITIALIZATION use this function :
# set_east_pin(east_yellow_pin=0,east_green_pin=0,east_red_pin=0);
#
# FOR WEST PIN INITIALIZATION use this function :
# set_west_pin(west_yellow_pin=0,west_green_pin=0,west_red_pin=0);
#
# FOR SOUTH PIN INITIALIZATION use this function :
# set_south_pin(south_yellow_pin=0,south_green_pin=0,south_red_pin=0);
#
# ----------NOTE : BY DEFAULT THE PINS ARE SET TO ZERO-----------------------------
# ---------------------------------------------------------------------------
#
# Set the pins High/on by using the function reset_pin():
# This will set all the pins high.
#
#
# Set the pins low/off by using the function set_all_pins():
# This will set all the pin low.
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
import machine
import time
def set_all_pins(north_yellow_pin=0,north_green_pin=0,north_red_pin=0,east_yellow_pin=0,east_green_pin=0,east_red_pin=0,west_yellow_pin=0,west_green_pin=0,west_red_pin=0,south_yellow_pin=0,south_green_pin=0,south_red_pin=0):
set_north_pin(north_yellow_pin=0,north_green_pin=0,north_red_pin=0);
set_east_pin(east_yellow_pin=0,east_green_pin=0,east_red_pin=0);
set_west_pin(west_yellow_pin=0,west_green_pin=0,west_red_pin=0);
set_south_pin(south_yellow_pin=0,south_green_pin=0,south_red_pin=0);
def set_east_pin(east_yellow_pin=0,east_green_pin=0,east_red_pin=0):
east_red = machine.Pin(east_red_pin, machine.Pin.OUT)
east_green = machine.Pin(east_green_pin, machine.Pin.OUT)
east_yellow = machine.Pin(east_yellow_pin, machine.Pin.OUT)
def set_west_pin(west_yellow_pin=0,west_green_pin=0,west_red_pin=0):
west_red = machine.Pin(west_red_pin, machine.Pin.OUT)
west_green = machine.Pin(west_green_pin, machine.Pin.OUT)
west_yellow = machine.Pin(west_yellow_pin, machine.Pin.OUT)
def set_north_pin(north_yellow_pin=0,north_green_pin=0,north_red_pin=0):
north_red = machine.Pin(north_red_pin, machine.Pin.OUT)
north_green = machine.Pin(north_green_pin, machine.Pin.OUT)
north_yellow = machine.Pin(north_yellow_pin, machine.Pin.OUT)
def set_south_pin(south_yellow_pin=0,south_green_pin=0,south_red_pin=0):
south_red = machine.Pin(south_red_pin, machine.Pin.OUT)
south_green = machine.Pin(south_green_pin, machine.Pin.OUT)
south_yellow = machine.Pin(south_yellow_pin, machine.Pin.OUT)
def on_all_pin():
north_red.on();
east_red.on();
west_red.on();
south_red.on();
# north red
north_red.on();
east_red.on();
west_red.on();
south_red.on();
# south red
north_red.on();
east_red.on();
west_red.on();
south_red.on();
#west red
north_red.on();
east_red.on();
west_red.on();
south_red.on();
def off_all_pin():
north_green.off();
north_yellow.off();
north_red.off();
east_green.off();
east_yellow.off();
east_red.off();
west_green.off();
west_yellow.off();
west_red.off();
south_green.off();
south_yellow.off();
south_red.off();
def northon():
# print("in north function");
pin_reset();
north_yellow.on();
time.sleep(0.5)
north_yellow.off();
north_green.on();
def easton():
# print("in east function");
pin_reset();
east_yellow.on();
time.sleep(0.5)
east_yellow.off();
east_green.on();
def weston():
# print("in west function");
pin_reset();
west_yellow.on();
time.sleep(0.5)
west_yellow.off();
west_green.on();
def southon():
# print("in south function");
pin_reset();
south_yellow.on();
time.sleep(0.5)
south_yellow.off();
south_green.on();
# print("start");
while True:
set_all_pins(13,14,12,21,22,23,5,18,19,15,4,2);
off_all_pin();
on_all_pin();
# north_green 14
# north_yellow 13
# north_red 12
# east_yellow 21
# east_green 22
# east_red 23
# west_yellow 5
# west_green 18
# west_red 19
# south_yellow 15
# south_green 4
# south_red 2
# yellow green red