Please help raspberry code

m1st3rz3r0

Honorary Poster
Please help

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
# Reader
GPIO.setup(4, GPIO.IN)
# Relay 1
GPIO.setup(25, GPIO.OUT)
# Relay 2
GPIO.setup(26, GPIO.OUT)
# Relay 3
GPIO.setup(16, GPIO.OUT)
# Button 1
GPIO.setup(23, GPIO.IN)
# Button 2
GPIO.setup(6, GPIO.IN)
# Button 3
GPIO.setup(17, GPIO.IN)
# Sensor 1
GPIO.setup(22, GPIO.IN)
# Sensor 2
GPIO.setup(5, GPIO.IN)

def small():
GPIO.output(25, GPIO.LOW)

def medium():
GPIO.output(26, GPIO.LOW)


print('Please swipe your card')
try:
while True:
reader=GPIO.input(4)
button1=GPIO.input(23)
button2=GPIO.input(6)
sensor1=GPIO.input(22)
sensor2=GPIO.input(5)

if reader==GPIO.HIGH:
print("select size")
button1==1
small()
button2==1
medium()
if sensor1==0:
GPIO.output(25, GPIO.HIGH)
time.sleep(1)
if sensor2==0:
GPIO.output(26, GPIO.HIGH)
time.sleep(1)
else:
(button1==0)
(button2==0)






finally:
GPIO.cleanup()
 
It looks like you're trying to control GPIO pins on a Raspberry Pi using Python. However, there are a few issues with your code.

1. In the lines button1==1 and button2==1, you are using the comparison operator == instead of the assignment operator =. To set the values of button1 and button2 to 1, you should use button1 = 1 and button2 = 1.

2. In the lines (button1==0) and (button2==0), you have E×ρréššions that are not assigned to any variable or used in any way. If you are trying to check the values of button1 and button2, you should use if button1 == 0: and if button2 == 0: instead.

Here's the corrected code:

Python:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Reader
GPIO.setup(4, GPIO.IN)
# Relay 1
GPIO.setup(25, GPIO.OUT)
# Relay 2
GPIO.setup(26, GPIO.OUT)
# Relay 3
GPIO.setup(16, GPIO.OUT)
# Button 1
GPIO.setup(23, GPIO.IN)
# Button 2
GPIO.setup(6, GPIO.IN)
# Button 3
GPIO.setup(17, GPIO.IN)
# Sensor 1
GPIO.setup(22, GPIO.IN)
# Sensor 2
GPIO.setup(5, GPIO.IN)

def small():
    GPIO.output(25, GPIO.LOW)

def medium():
    GPIO.output(26, GPIO.LOW)

print('Please swipe your card')

try:
    while True:
        reader = GPIO.input(4)
        button1 = GPIO.input(23)
        button2 = GPIO.input(6)
        sensor1 = GPIO.input(22)
        sensor2 = GPIO.input(5)

        if reader == GPIO.HIGH:
            print("select size")
            button1 = 1
            small()
            button2 = 1
            medium()
        
        if sensor1 == 0:
            GPIO.output(25, GPIO.HIGH)
            time.sleep(1)
        
        if sensor2 == 0:
            GPIO.output(26, GPIO.HIGH)
            time.sleep(1)
        
        if button1 == 0:
            # Do something when button1 is pressed
            pass
        
        if button2 == 0:
            # Do something when button2 is pressed
            pass

finally:
    GPIO.cleanup()

Please note that I have left the if button1 == 0 and if button2 == 0 sections empty as you need to define what actions you want to perform when those buttons are pressed.
 

About this Thread

  • 1
    Replies
  • 370
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,096
Guests online
1,173
Total visitors
2,269

Forum statistics

Threads
2,273,809
Posts
28,951,896
Members
1,234,967
Latest member
hunterzz007
Back
Top