Пример #1
0
 def loop_time(self):
     if ranges.inrange():
         print('Timeout: switch on')
         relay.set(1)
     else:
         print('Timeout: switch off')
         relay.set(0)
     register(relay.status())
Пример #2
0
    def __init__(self, timeout=10):
        self.counter = 0
        self.presence = 0
        self.before = 0
        self.timeout = timeout

        # Let's start
        relay.set(0)
        print('Relay ready', self.timeout)
Пример #3
0
    def loop(self):
        if not ranges.inrange():
            relay.set(0)
            return

#Get Sensor presence
#print('Waiting PIR...')
        self.presence = pir.get()
        if self.presence:
            if not self.before:
                print('Switch on')
                relay.set(1)
                self.counter = 0
                register(relay.status())
        elif relay.get() == 1:
            self.counter += 1
            if self.counter > self.timeout:
                print('Timeout: switch off')
                relay.set(0)
                self.counter = 0
                register(relay.status())
            else:
                print(self.counter, end='..')

    # Save it for next loop
        self.before = self.presence
Пример #4
0
 def switch_off(self):
     self.counter = 0
     relay.set(0)
     return 'Off!'
Пример #5
0
 def switch_on(self):
     self.counter = 0
     relay.set(1)
     return 'On!'