What's new

Please help raspberry code

Pnoy

Addict
Joined
Nov 10, 2016
Posts
148
Reaction
13
Points
99
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 expressions 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.
 

Similar threads

Back
Top