Beispiel #1
0
class AnimalAlert():
    def __init__(self):
        self.iot = Startiot()
        self.iot.connect(False)
        self.py = Pysense()
        """
		self.gps = L76GNSS(py, timeout = 30)
		(self.lat, self.lng) = self.gps.coordinates()
		self.counter = 0
		"""
        self.state = STATE_IDLE

        self.rightpir = Pir("P11")
        self.centerpir = Pir("P2")
        self.leftpir = Pir("P9")
        self.led = Led("P10")
        self.i2c = I2C(1, I2C.MASTER, baudrate=100000, pins=("P4", "P8"))
        self.uv_sensor = VEML6070.VEML6070_UV(self.i2c)
        self.baseline = []
        pycom.heartbeat(False)  # disable the blue blinking

    """
	def get_gps(self):		
		if (self.lat, self.lng) == (None, None):
			(self.lat, self.lng) = self.gps.coordinates()
		else: 
			if self.counter < GPS_NUMCOPIES:
				(self.lat, self.lng) = (self.lat, self.lng)
				self.counter += 1
			else: 
				self.counter = 1
				(self.lat, self.lng) = self.gps.coordinates()

		return(self.lat, self.lng)
	"""

    def uv_baseline(self, uv):
        if len(self.baseline) == BASELINE_MAX:
            self.baseline.pop(0)
            self.baseline.append(uv)
        else:
            self.baseline.append(uv)

        average = sum(self.baseline) / len(self.baseline)
        return average

    def notify(self, left, center, right):
        data = "{},{},{}".format(left, center, right)
        if center == 1:
            self.state = STATE_WARNING
            self.led.blink(LED_DELAY, LED_DURATION)
            self.iot.send(data)
            print("sent to startIoT")

        elif left == 1 or right == 1:
            self.state = STATE_ALERT
            self.led.blink(LED_DELAY, LED_DURATION)
            self.iot.send(data)
            print("sent to startIoT")

        #(lat, lng) = self.get_gps()
        #data = "{},{},{},{},{},{}".format(left, center, right, lat, lng, uv)

    def run(self):
        # main loop
        while True:
            centerval = self.centerpir.check_sensor()
            rightval = self.rightpir.check_sensor()
            lefval = self.leftpir.check_sensor()
            uv = self.uv_sensor.read()

            average = self.uv_baseline(uv)
            print(lefval, centerval, rightval, uv, average)

            if centerval == 1 or lefval == 1 or rightval == 1:
                if uv > average + BASELINE_DIFF:
                    pass
                else:
                    self.notify(lefval, centerval, rightval)
                    self.state = STATE_IDLE

            self.led.stop
            sleep(SLEEPTIME_MAIN)
Beispiel #2
0
beeper = Led(BEEPER, name='BEEPER', debug=IS_DEBUG)

# init Key DB
key_db = KeyDB()

# init wlan
init_wlan()

lock = _thread.allocate_lock()

# create udp server thread
_thread.start_new_thread(udp_ser, (ip, port))

print('Complete.')

beeper.blink()

print("")
print("Working...")
print("")

try:
    while True:
        open_status = False

        # reading card
        (stat, tag_type) = rdr.request(rdr.REQIDL)
        if stat == rdr.OK:
            (stat, raw_uid) = rdr.anticoll()
            if stat == rdr.OK:
                card_uid = raw_uid[0] + raw_uid[1] * 256 + raw_uid[2] * 100000
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pingo
from led import Led
import time


board = pingo.detect.get_board()
red_led_pin = board.pins[12]    # GPIO18
r_led = Led(red_led_pin)

r_led.blink(times=10, on_delay=0.1, off_delay=None)
print(r_led.blinkThread.isAlive())

while(r_led.blinkThread.active):
    # if(r_led.blinkThread.isAlive()):
    print(r_led.blinkThread.active)
    time.sleep(0.5)
print(r_led.blinkThread.isAlive())
Beispiel #4
0
        while count < wait_ms:
            if not self.btn.value():
                count += 1
            else:
                return False
            sleep_ms(1)
        return True

    
    def is_pressed(self):
        return self.wait_pin_change()


if __name__ == '__main__':
    from led import Led

    LED_PIN = 25
    BTN_PIN = 22

    led = Led(LED_PIN)
    btn = BtnSwitch(BTN_PIN)

    try:
        while True:
            btn_motion = False
            if btn.is_pressed():
                print('Key Pressed', btn.pin_no)
                led.blink()
    except KeyboardInterrupt:
        print("Bye")
Beispiel #5
0
# set it all up like usual
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

# create leds
timingLed = Led(PIN1)  # keeps a steady pace
notifyingLed = Led(PIN2)  # will change based on how close we are to the end

counter = TIME  #set the counter to be the same as the seconds
third = math.floor(TIME / 3)
twothirds = third * 2
half = math.floor(TIME / 2)

while (counter > 0):
    counter -= 1  #step backwards by one
    time.sleep(1)
    timingLed.toggle()  #put the led in the opposite state it was in before

    # first third
    if (counter > half and counter < twothirds):
        notifyingLed.on()

    # halfway
    if (counter <= half and counter > third):
        notifyingLed.toggle()

    # last third
    if (counter <= third):
        notifyingLed.blink(2, .05)
Beispiel #6
0

first = button_left.state() 
second = button_right.state()

currentColor = led_green
currentColor.on()
last_change_time = ticks_ms()

while True:
  first = button_left.state()
  second = button_right.state()
  
  if first and not second: #amarelo intermitente
    currentColor.off()
    led_yellow.blink(1000)
    while first: #esperar que o user deixe de pressionar o botao
      first = button_left.state()
  
    while not first:
      led_yellow.proc()
      first = button_left.state()
    
    led_yellow.off()
    currentColor.on()
    last_change_time = ticks_ms()
    while first:  #esperar que o user deixe de pressionar o botao
      first = button_left.state()
  
  first = button_left.state()
  second = button_right.state()
Beispiel #7
0
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.cleanup()
import time
import sys
sys.path.insert(0, '/home/pi/pi-projects/libs')

from led import Led

led = Led(4)

led.stopBlink()

#led.blink(0.1)

print "sfsdf"

led.blink(1)
time.sleep(4)
led.blink(0.1)
time.sleep(4)
led.blink(1)
led.off()

print "sfsdf"