from machine import Pin, ADC
import utime
from neopixel import NeoPixel
#from time import sleep
trigger = Pin(18, Pin.OUT) # gpio 18 = pico pin 24
echo = Pin(17, Pin.IN) # gpio 17 = pico pin 22
NUMBER_PIXELS_TOP = 100
NUMBER_PIXELS_SIDE = 100
LED_PIN_SIDE = 6 #gpio 6
LED_PIN_TOP = 7 #gpio 7
brightness = 100
red = (brightness, 0, 0)
blue = (0, 0, brightness)
last_top = 0
last_side = 0
# distance sensor readings
def ultra():
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)
trigger.low()
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
print("The distance from object is ",distance)
while True:
()
utime.sleep(.5)
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(5)
trigger.low()
while echo.value() == 0:
signaloff = utime.ticks_us()
while echo.value() == 1:
signalon = utime.ticks_us()
timepassed = signalon - signaloff
distance = (timepassed * 0.0343) / 2
print("The distance from object is ",distance)
###### old pot to led strip code
#while True:
potentiometer_value = machine.ADC(27) # GPIO 27 = Pico pin 32
potreading = potentiometer_value.read_u16()
#print("The potentiometer reading is ",potreading*5/65000,"something")
# print("The distance from object is ",distance/2.54,"inches\n\n")
# i = int(potreading*5/65000)
i = int(distance)
#i = distance
strip = NeoPixel(Pin(LED_PIN_TOP), NUMBER_PIXELS_TOP)
strip[last_top] = (0,0,0)
strip[i] = red
strip.write()
last_top = i
print(i)
# j = int(potreading*39/65000)
j = int(distance)
side = NeoPixel(Pin(LED_PIN_SIDE), NUMBER_PIXELS_SIDE)
side[last_side] = (0,0,0)
side[j] = blue
side.write()
last_side = j