Hello,
I am new to this forum and just started with Rasberry Pi 4 model B and I started my electronics journey. I am a beginner with Python and Have some understanding but as you will see below there is a knowledge gap in my code..
-------I got my breadboard and code on Thonny working, I can press the button and the LED light illuminates however I attempted to code an if/else statement to display that I clicked the button on my terminal .
But I get a syntax error in regards to the '=' in the if statement so I imagine then that only a '==' type can be used
My other thought is if/else statements cannot be used with the OOP...
Anyways if someone could kindly provide the right code and explanation as to why my code does not work.
I am new to this forum and just started with Rasberry Pi 4 model B and I started my electronics journey. I am a beginner with Python and Have some understanding but as you will see below there is a knowledge gap in my code..
-------
Code:
from gpiozero import LED, Buttonfrom signal import pauseled = LED(17)button = Button(2)button.when_pressed = led.onbutton.when_released = led.offpause()
Code:
from gpiozero import LED, Buttonfrom signal import pauseled = LED(17)button = Button(2)if button.when_pressed = led.on: print("BUTTON PRESSED!)elif button.when_released = led.off print("BUTTON RELEASED!)pause()
My other thought is if/else statements cannot be used with the OOP...
Anyways if someone could kindly provide the right code and explanation as to why my code does not work.
Statistics: Posted by cybersamuraii33 — Tue Jan 23, 2024 1:19 pm