This commit is contained in:
Chizuui
2025-11-27 06:29:14 +07:00
parent 1795fa1c2f
commit cfb042fc48
912 changed files with 167150 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import time
from machine import ADC, Pin
ldr = ADC(0)
# 1. Gabungkan semua LED ke dalam satu list
lamp = [
Pin(15, Pin.OUT), # led1
Pin(13, Pin.OUT), # led2
Pin(12, Pin.OUT), # led3
Pin(14, Pin.OUT), # led4
Pin(16, Pin.OUT), # led5
]
# Threshold LED (contoh)
thresholds = [1024, 900, 700, 500, 300]
while True:
value = ldr.read() # 0 - 1023
print("LDR:", value)
for i in range(len(lamp)): # mengambil range dari variable lamp
# Mengambil led dan threshold menggunakan index 'i'
led = lamp[i]
threshold = thresholds[i]
if value < threshold: # jika nilai LDR lebih kecil dari threshold
led.on() # led menyala
else: # jika nilai led lebih besar dari trasehold
led.off() # maka led akan mati
time.sleep_ms(10)

View File

@@ -0,0 +1,14 @@
import time
from machine import Pin
led=Pin(2,Pin.OUT)
try:
while True:
led.value(1)
time.sleep(0.5)
led.value(0)
time.sleep(0.5)
except KeyboardInterrupt:
led.value(1)
pass