Skip to content

Instantly share code, notes, and snippets.

@shikarunochi
Created October 8, 2018 04:12
Show Gist options
  • Save shikarunochi/4c513ec6edd3dc483f9f6a13c0786ee0 to your computer and use it in GitHub Desktop.
Save shikarunochi/4c513ec6edd3dc483f9f6a13c0786ee0 to your computer and use it in GitHub Desktop.
M5Stack Sync Photocell Reveiver
from m5stack import lcd
import time
import machine
lcd.clear()
lcd.setCursor(0, 0)
lcd.setColor(lcd.WHITE)
dataPin = machine.ADC(machine.Pin(36, machine.Pin.IN))
dataPin.atten(machine.ADC.ATTN_11DB)
syncPin = machine.ADC(machine.Pin(35, machine.Pin.IN))
syncPin.atten(machine.ADC.ATTN_11DB)
OFFcheckValue = 600
ONcheckValue = 900
#スピーカー音を消す
#http://t-yosh.hatenablog.com/entry/2017/12/28/235947
dac = machine.DAC(machine.Pin(25))
dac.write(0)
lcd.font(lcd.FONT_Comic)
lcd.clear()
lcd.setCursor(0, 0)
syncPinValue = 0
x = 0
y = 0
while True:
#syncPinがONになるのを待つ
while syncPinValue < ONcheckValue:
syncPinValue = syncPin.read()
time.sleep_ms(50)
print ("IN:" + str(syncPinValue) + "\n")
#dataを読む
value = dataPin.read()
if value > ONcheckValue:
lcd.print("1")
else:
lcd.print("0")
x = x + 1
if x >= 8:
x = 0
y = y + 1
lcd.setCursor(x * 25, y * 25)
time.sleep_ms(50)
#syncPinがOFFになるのを待つ
while syncPinValue > OFFcheckValue:
syncPinValue = syncPin.read()
time.sleep_ms(50)
print ("OUT:" + str(syncPinValue) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment