Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. # WeBadge for DefCon#27
  2. # From your friends in We Work InfoSec
  3. # Makes buddies with up to 4 Shitty Add-Ons
  4. import board
  5. import time
  6. import busio
  7. from digitalio import DigitalInOut, Direction, Pull
  8. from analogio import AnalogIn
  9. from pulseio import PWMOut
  10.  
  11. # The "W" and "E" Leds. Use PulseIO to PWM the brightness
  12. e = PWMOut(board.LEDE, frequency=5000, duty_cycle=0)
  13. w = PWMOut(board.LEDW, frequency=5000, duty_cycle=0)
  14.  
  15. # Init the photosensor, get a reading to set LED brightness
  16. photocell = AnalogIn(board.PHOTO)
  17. def getMaxBright():
  18. #return min(photocell.value + 3000, 65535)
  19. return min(photocell.value, 65535)
  20.  
  21. # Setup the Shitty Add-Ons so they have power (we can PWM only POW1)
  22. power1 = PWMOut(board.POW1, frequency=5000, duty_cycle=0)
  23. power2 = DigitalInOut(board.POW2)
  24. power2.direction = Direction.OUTPUT
  25. power3 = DigitalInOut(board.POW3)
  26. power3.direction = Direction.OUTPUT
  27. power4 = DigitalInOut(board.POW4)
  28. power4.direction = Direction.OUTPUT
  29.  
  30. t = 0
  31. x0 = 0
  32. x1 = 0
  33. x2 = 0
  34. y1 = 0
  35. t = 0
  36. THRESHOLD = 10000
  37. INTERVAL = 0.02
  38. BRIGHTNESS = 60000
  39.  
  40. def on_detection():
  41. global w, e
  42. for i in range(4):
  43. w.duty_cycle = 0
  44. e.duty_cycle = BRIGHTNESS
  45. time.sleep(0.25)
  46. w.duty_cycle = BRIGHTNESS
  47. e.duty_cycle = 0
  48. time.sleep(0.25)
  49.  
  50. def main():
  51. while True:
  52. # input
  53. x = int(photocell.value)
  54. x2 = x1
  55. x1 = x0
  56. x0 = x
  57. # apply a high-pass filter
  58. y = (x2 + x0 - x1 - x1)
  59. if y < 0:
  60. y = -y # diode
  61. y = max(0, min(65535, y))
  62. # apply exponential smoothing so we don't flash right away
  63. y1 = y1 * 0.9 + y * 0.1
  64. if y1 > THRESHOLD:
  65. # Flash to indicate signal detection
  66. on_detection()
  67. # reset state
  68. y1 = y = 0
  69. x1 = x0 = x2 = x = 0
  70.  
  71. t = 1 - t
  72. w.duty_cycle = e.duty_cycle = int(BRIGHTNESS * t)
  73. time.sleep(INTERVAL)
  74.  
  75. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement