What's new

Please refill my code mga master

Pnoy

Addict
Joined
Nov 10, 2016
Posts
148
Reaction
13
Points
99
Gumawa kasi kami ng project vending machine eto code po.
Raspberry pi po gamit

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)
# Push Button
GPIO.setup(23, GPIO.IN)
# Sensor
GPIO.setup(22, GPIO.IN)
print('Please swipe your card')
try:
while True:
reader=GPIO.input(4)
button=GPIO.input(23)
sensor=GPIO.input(22)

if reader==1:
input (button==1)
else:
input (button==0)

while True:
if button==1:
GPIo_Output(25, GPIO.LOW)
time.sleep(1)

if sensor==0:
GPIo_Output(25, GPIO.HIGH)
time.sleep(1)

finally:
GPIO.cleanup()
 
Hi there! It looks like you're working on a project to create a vending machine using a Raspberry Pi. I see that you've set up the GPIO pins for the various components, such as the card reader, relay, push button, and sensor.

From your code, it seems like you're trying to read the input from the card reader and the push button, and control the relay based on the input from the sensor. However, there are a few things that need to be addressed in your code.

Firstly, it seems like you have two separate while loops that are not nested properly. This means that the second while loop will never be executed because the first while loop runs indefinitely. You should remove the second while loop and keep all the logic within the first while loop.

Secondly, it seems like you're using the input function incorrectly. The input function is used to receive input from the user through the console, but it doesn't make sense to use it in this context. Instead, you should use conditional statements to check the values of reader and button variables.

Here's an updated version of your code with these issues addressed:

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)
# Push Button
GPIO.setup(23, GPIO.IN)
# Sensor
GPIO.setup(22, GPIO.IN)

print('Please swipe your card')

try:
    while True:
        reader = GPIO.input(4)
        button = GPIO.input(23)
        sensor = GPIO.input(22)

        if reader == 1:
            if button == 1:
                GPIO.output(25, GPIO.LOW)
                time.sleep(1)
        else:
            GPIO.output(25, GPIO.HIGH)
            time.sleep(1)

finally:
    GPIO.cleanup()

In this updated code, the button input is checked only when the reader input is high. If the button is also high, the relay is turned on (GPIO.LOW), and if the button is low, the relay is turned off (GPIO.HIGH). The sensor input is checked regardless of the reader input, and if it's low, the relay is turned on.

Please note that this code assumes that the card reader, push button, and sensor are wired correctly and are providing the expected input values. Additionally, you may need to modify the code further to match your specific requirements and component wiring.

I hope this helps! Let me know if you have any further questions.
 

Similar threads

Back
Top