Code: Select all
from machine import Pin
from time import sleep
#class Opto setup to handle an expandable number of sensors
class Opto ():
def __init__(self, name, sensor, motor):
self.name = name
self.sensor = sensor
self.motor = motor
def stop(self):
if sensor.value() == 1: <—line 11
motor.value(0)
print(name, "stopped")
#one sensor for test. Input on pin 4, output on pin 5.
opto1 = Opto("opto1", Pin(4, Pin.IN, Pin.PULL_DOWN), Pin(5, Pin.OUT))
#other variables
led = Pin(5, Pin.OUT)
#main loop
while True:
led.value(1)
opto1.stop() <—line 23
sleep(1)
///////////////////////////////////////////
Ready to download this file,please wait!
…..
download ok
exec(open(‘function interrupt test.py’).read(),globals())
Traceback (most recent call last):
File”<stdin>”, line 1, in <module>
File”<string>”, line 23, in <module>
File”<string>”, line 11, in stop
NameError: name ‘sensor’ isn’t defined