I am working on a project, with MicroPython.
Hardware: LoPy 4 + 3.0 expansion board, 1 button, 1 led, 2 resistors (1k)
Schematic (Red wires are P13 and P15)
And my code:
import machine
from machine import Pin
import time
button1 = "P13"
LED = "P15"
button_1 = Pin(button1, mode=Pin.IN)
led = Pin(LED, mode=Pin.OUT)
def button_press():
while True:
if button_1.value():
led.value(1)
print('Button pressed...')
print('Sensor is HIGH')
time.sleep(0.5)
def main():
button_press()
if __name__ == "__main__":
main()
Problem: For some reason, I don't know if it is an hardware issue or a problem with my code. But I already get values without pressing the button
So for some reason I already get the print without pressing the button. And I can't figure it out, does someone know a solution?
Thanks in advance?