-
-
Save ihfazhillah/c86b67288225efb852c103f2e6a7d30b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin | |
import time | |
led_red = Pin(16, Pin.OUT) | |
green_led = Pin(17, Pin.OUT) | |
yellow_led = Pin(18, Pin.OUT) | |
push_btn = Pin(15, Pin.IN, Pin.PULL_DOWN) | |
latest_click = time.ticks_ms() | |
delay = 300 # in ms | |
def nyala_semua(): | |
led_red.value(1) | |
green_led.value(1) | |
yellow_led.value(1) | |
def mati_semua(): | |
led_red.value(0) | |
green_led.value(0) | |
yellow_led.value(0) | |
def kedip_bareng(): | |
nyala_semua() | |
time.sleep(0.5) | |
mati_semua() | |
time.sleep(0.5) | |
def kedip_1_per_1(): | |
mati_semua() | |
time.sleep(0.5) | |
led_red.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
yellow_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
green_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
def kedip_2_bergantian(): | |
mati_semua() | |
time.sleep(0.5) | |
led_red.value(1) | |
yellow_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
green_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
led_red.value(1) | |
green_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
yellow_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
yellow_led.value(1) | |
green_led.value(1) | |
time.sleep(0.5) | |
mati_semua() | |
led_red.value(1) | |
time.sleep(0.5) | |
states = [mati_semua, nyala_semua, kedip_bareng, kedip_1_per_1, kedip_2_bergantian] | |
current_state = 0 | |
def handle_toggle(pin): | |
global latest_click, current_state | |
if (time.ticks_ms() - latest_click) > delay and pin.value(): | |
latest_click = time.ticks_ms() | |
current_state += 1 | |
push_btn.irq(handle_toggle, trigger=Pin.IRQ_RISING) | |
while True: | |
state_fn = states[current_state % 5] | |
state_fn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment