0

I am trying to write a loop to read pin 14 on a pi pico. Normally the pin will be 0 (Low) but when it goes 1 (High) I would like to exit the while loop and continue with the rest of the script. I have it running and it is printing "HELLO" but when I put a high on pin 14 it doesn't "break". What I have just for this while portion is as follows:

import machine
from machine import Pin
import utime
from machine import Timer

#Create input for Pin 4
p14 = Pin(14, Pin.IN)

#Set Pin 14 Value Low Initially
#p14.value(1)

#(Section is for reading Input High on Pin 4)
check = (p14.value())
print(p14.value())
while check != 1:
  check2 = (p14.value())
  print("HELLO")
  if check2 == 1:
      print("Pin 14 went HIGH")
      break

I've tried numerous iterations of while but still cannot get this to work.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
Brian
  • 17
  • 1
  • 1
  • 2
  • I have no logs. And I never get Pin 14 went high message only the constant scrolling HELLO even when I jumper pin 36 (3.3VDC) to pin 19 (GPIO 14) – Brian May 14 '23 at 05:08
  • 2
    You read the pin and assign it to `check` outside of the loop. You test `check` every time through the loop, but you never update it. Simplify the loop, get rid of all the 'check's and test the pin value directly in the `while` condition. Also, you might want to use `Pin(14, Pin.IN, Pin.PULL_UP)` Have fun! – aMike May 14 '23 at 12:57

0 Answers0