'''
#program 1
from machine import Pin
from time import sleep
tombol = Pin(14, Pin.IN)
count =0
while True:
if tombol.value() == 0: # Tombol ditekan (active low)
print("Tombol ditekan")
count=count+1
print(count)
sleep(0.01) # Delay
'''
#pada program 1, terjadi loncatan nilai count yang besar saat 1x tombol ditekan, padahal seharusnya
#untuk 1x tekan tombol, nilai count hanya bertambah +1
#program 2
from machine import Pin
from time import sleep
button = Pin(14, Pin.IN, Pin.PULL_UP)
count = 0
last_state = 1
while True:
state = button.value()
if state == 0 and last_state == 1:
print("Button pressed")
count += 1
print(count)
sleep(0.01)
last_state = state
sleep(0.01)
#pada program 2, dengan menambahkan resistor dan pull_up, maka saat button ditekan 1x nilai count hanya
#bertambah 1x