Skip to content

first commit air blaster code #2909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Haunt_Air_Blaster/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SPDX-FileCopyrightText: 2024 John Park for Adafruit Industries
#
# SPDX-License-Identifier: MIT
'''
Air Blaster
Feather RP2040 Prop-Maker with Power Relay FeatherWing and VL53L1X distance sensor
'''

import time
import board
import digitalio
import adafruit_vl53l1x

TRIGGER_DISTANCE = 50.0
triggered = False

i2c = board.STEMMA_I2C()
vl53 = adafruit_vl53l1x.VL53L1X(i2c)
vl53.distance_mode = 2
vl53.timing_budget = 100

print("VL53L1X Simple Test.")
print("--------------------")
model_id, module_type, mask_rev = vl53.model_info
print("Model ID: 0x{:0X}".format(model_id))
print("Module Type: 0x{:0X}".format(module_type))
print("Mask Revision: 0x{:0X}".format(mask_rev))
print("Distance Mode: ", end="")
if vl53.distance_mode == 1:
print("SHORT")
elif vl53.distance_mode == 2:
print("LONG")
else:
print("UNKNOWN")
print("Timing Budget: {}".format(vl53.timing_budget))
print("--------------------")

vl53.start_ranging()

relay_pin = digitalio.DigitalInOut(board.D10)
relay_pin.direction = digitalio.Direction.OUTPUT
relay_pin.value = False

def blast(repeat, duration, rate):
for _ in range(repeat):
relay_pin.value = True
print("bang")
time.sleep(duration)
relay_pin.value = False
time.sleep(rate)

distance = None

while True:
if vl53.data_ready:
distance = vl53.distance
print("Distance: {} cm".format(vl53.distance))
vl53.clear_interrupt()
time.sleep(0.1)

if distance:
if distance <= TRIGGER_DISTANCE:
if not triggered :
blast(3, 0.01, 0.1) # adjust repeat, duration, rate here
time.sleep(0.4)
blast(2, 0.01, 0.2) # adjust repeat, duration, rate here
triggered = True

else:
triggered = False