2021-08-16
Actuator, NFC, Python, Raspberrypi, Sensor
switch LED by nfc(suica)
install nfcpy
忘れたけどたぶん
pip install nfcpy
でインストール
say hello
import nfc
def say_hello (tag): print('hello') clf = nfc.ContactlessFrontend('usb')rdwr = {'on-connect': say_hello}
print('start')clf.connect(rdwr=rdwr)print('end')
で, 最初のテスト. suicaを載せると"hello"と喋る. 一回きり.
Lチカ
Lチカに移る. +は7番. -はGND.
import nfcimport RPi.GPIO as GPIOimport timeGPIO.setmode(GPIO.BOARD)GPIO.setup(7, GPIO.OUT)
GPIO.output(7, False)
def turn_led (tag): is_turn = GPIO.input(7) print(is_turn) if(is_turn): GPIO.output(7, False) else: GPIO.output(7, True)
time.sleep(1) clf = nfc.ContactlessFrontend('usb')
rdwr = {'on-connect':turn_led}
while True: print('waiting...') clf.connect(rdwr=rdwr) print('scaned')
suicaをタッチするたびにLEDがON/OFFする.
timeの1秒はタッチの反応が連続して動作しないようにするため.
