Created
August 4, 2023 20:15
-
-
Save gustavolaureano/2a22a55951e6de8192e117d560d261e3 to your computer and use it in GitHub Desktop.
Revisions
-
gustavolaureano created this gist
Aug 4, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ import machine, neopixel, time from machine import Pin, ADC np = neopixel.NeoPixel(Pin(2), 200) adcpin = machine.ADC(26) while True: num_of_leds = None for i in range(len(np)): onvalue = 0 offvalue = 0 for t in range(10): np[i] = (255, 255, 255) np.write() onvalue += adcpin.read_u16() np[i] = (0, 0, 0) np.write() offvalue += adcpin.read_u16() dist = abs(onvalue - offvalue) #print(f"{i+1} on: {onvalue} off: {offvalue} dist: {dist}") if (dist < 1100): num_of_leds = i break if (num_of_leds): print(f"Found: {num_of_leds}") else: print(f"No LEDs found.") time.sleep(3)