Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # WeBadge for DefCon#27
- # From your friends in We Work InfoSec
- # Makes buddies with up to 4 Shitty Add-Ons
- import board
- import time
- import busio
- from digitalio import DigitalInOut, Direction, Pull
- from analogio import AnalogIn
- from pulseio import PWMOut
- # The "W" and "E" Leds. Use PulseIO to PWM the brightness
- e = PWMOut(board.LEDE, frequency=5000, duty_cycle=0)
- w = PWMOut(board.LEDW, frequency=5000, duty_cycle=0)
- # Init the photosensor, get a reading to set LED brightness
- photocell = AnalogIn(board.PHOTO)
- def getMaxBright():
- #return min(photocell.value + 3000, 65535)
- return min(photocell.value, 65535)
- # Setup the Shitty Add-Ons so they have power (we can PWM only POW1)
- power1 = PWMOut(board.POW1, frequency=5000, duty_cycle=0)
- power2 = DigitalInOut(board.POW2)
- power2.direction = Direction.OUTPUT
- power3 = DigitalInOut(board.POW3)
- power3.direction = Direction.OUTPUT
- power4 = DigitalInOut(board.POW4)
- power4.direction = Direction.OUTPUT
- t = 0
- x0 = 0
- x1 = 0
- x2 = 0
- y1 = 0
- t = 0
- THRESHOLD = 10000
- INTERVAL = 0.02
- BRIGHTNESS = 60000
- def on_detection():
- global w, e
- for i in range(4):
- w.duty_cycle = 0
- e.duty_cycle = BRIGHTNESS
- time.sleep(0.25)
- w.duty_cycle = BRIGHTNESS
- e.duty_cycle = 0
- time.sleep(0.25)
- def main():
- while True:
- # input
- x = int(photocell.value)
- x2 = x1
- x1 = x0
- x0 = x
- # apply a high-pass filter
- y = (x2 + x0 - x1 - x1)
- if y < 0:
- y = -y # diode
- y = max(0, min(65535, y))
- # apply exponential smoothing so we don't flash right away
- y1 = y1 * 0.9 + y * 0.1
- if y1 > THRESHOLD:
- # Flash to indicate signal detection
- on_detection()
- # reset state
- y1 = y = 0
- x1 = x0 = x2 = x = 0
- t = 1 - t
- w.duty_cycle = e.duty_cycle = int(BRIGHTNESS * t)
- time.sleep(INTERVAL)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement