]> vault307.fbx.one Git - random.git/blob - photocellCounter.py
different projects to learn new things
[random.git] / photocellCounter.py
1 #!/usr/bin/env micropython
2 from machine import ADC, Pin
3 from time import sleep
4 from machine import RTC
5
6
7
8 photoPIN=26
9 led=Pin(13,Pin.OUT)
10 rtc=RTC()
11
12
13 def readLight(photoGP):
14 photoRes=ADC(Pin(26))
15 light=photoRes.read_u16()
16 light=round(light/65535*100,2)
17 return light
18
19 file=open('photoLog.txt','w')
20 while True:
21 file.write("light: "+str(readLight(photoPIN))+"%"+ str(rtc.datetime())+"\n")
22 file.flush()
23 print("light: " + str(readLight(photoPIN)) +"%")
24 print(rtc.datetime())
25 sleep(900)
26