Skip to content

Instantly share code, notes, and snippets.

@gustavolaureano
Created August 4, 2023 20:15
Show Gist options
  • Select an option

  • Save gustavolaureano/2a22a55951e6de8192e117d560d261e3 to your computer and use it in GitHub Desktop.

Select an option

Save gustavolaureano/2a22a55951e6de8192e117d560d261e3 to your computer and use it in GitHub Desktop.

Revisions

  1. gustavolaureano created this gist Aug 4, 2023.
    29 changes: 29 additions & 0 deletions main.py
    Original 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)