from machine import Pin
from time import sleep
led_pin = Pin(12,Pin.OUT)
button_pin = Pin(18,Pin.IN,Pin.PULL_UP)
# that is button is not pressed
current_button_state = 0
# that is initially button is not pushed or pressed eith
previous_button_state = 0
button_debounce_time = 0.01 # seconds
led_state = False
lists = [[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]]
current_index = 0
while True:
# now when changing the current_button_state to the button.value() whatever it is 0 or 1.
current_button_state = button_pin.value()
sleep(button_debounce_time)
# what does the following condition means will it means that if the current_button_state got 1 from the button_pin.value
# and the previous_button_state is not changed that is 0 that means that button is pressed
if current_button_state == 1 and previous_button_state == 0:
led_state = not led_state
led_pin(led_state)
current_list = lists[current_index]
print("Current List:", current_list)
current_index = (current_index + 1) % 5
# and now we going to update the previous state to the current state so that if statement does not execute again and once button is pressed the current state will change again and if statement will hold true
previous_button_state = current_button_state # which is 1
for i in current_list:
print(i,end="")