'''
PROJECT TWO
This example demonstrates how to configure MULTIPLE GPIO pins as outputs to
which LEDS are connected.
A light chasing sequence is observed on 3 LEDS
Connection requirements
Connect EACH LED through a resistor, 2K2 down to the GND pin.
Starting from the leftmost LED
LED1 --> GPIO21
LED2 --> GPIO19
LED3 --> GPIO18
LED4 --> GPIO5
Reference material
https://docs.micropython.org/en/latest/esp32/quickref.html#pins-and-gpio
NOTE THAT THE CODE BELOW IS NOT EFFICIENTLY WRITTEN. HOW CAN THIS BE CODED MORE
EFFICIENTLY.
'''
from machine import Pin, Timer # Contains specific functions related to the # hardware on a particular board
from time import sleep # module that contains time related functions
led_21 = Pin(21, Pin.OUT) # create output pin on GPIO21
led_19 = Pin(19, Pin.OUT) # create output pin on GPIO19
led_18 = Pin(18, Pin.OUT) # create output pin on GPIO18
led_5 = Pin(5, Pin.OUT)
# Define functions used
i = 0
def binarycount(x):
binary='{0:04b}'.format(x)
led_21.value(int(binary[0]))
led_19.value(int(binary[1]))
led_18.value(int(binary[2]))
led_5.value(int(binary[3]))
def handler_0(tim0):
global i
count = [0, 1, 2, 3]
binarycount(2**count[i])
i=i+1
if i==4:
i=0
tim0 = Timer(0)
tim0.init(period=1000 , mode=Timer.PERIODIC, callback=handler_0)