Skip to content

Commit 2995af0

Browse files
author
Sebastian Goscik
committed
Added library for ALS PT19 Analog Light Sensor
1 parent 61eb578 commit 2995af0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/ALSPT19/ALSPT19.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from machine import ADC
2+
import time
3+
4+
class ALSPT19(object):
5+
def __init__(self, pin_name):
6+
adc = ADC()
7+
self.pin = adc.channel(pin=pin_name, attn=ADC.ATTN_11DB, bits=12)
8+
self.threshold = None
9+
10+
def calibrate(self, samples=300):
11+
max_val = 0
12+
for _ in range(samples):
13+
val = self.pin()
14+
if val > max_val:
15+
max_val = val
16+
time.sleep_ms(10)
17+
18+
self.threshold = max_val * 1.2
19+
20+
def is_on(self):
21+
if self.pin() > self.threshold:
22+
return True
23+
return False

0 commit comments

Comments
 (0)