What's new

Help pls

Pnoy

Addict
Joined
Nov 10, 2016
Posts
148
Reaction
13
Points
99
Hello phcbot please help

Upgrade to a smarter Gmail
Secure, fast & organized email
You do not have permission to view the full content of this post. Log in or register now.


If you're having trouble loading, visit the You do not have permission to view the full content of this post. Log in or register now..


Primary










codes to test



Prince Baylon






Prince Baylon
to me
0 minutes ago
Details
import RPi.GPIO as GPIO
import time

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



# Relay 1
GPIO.setup(25, GPIO.OUT)
# Push Button
GPIO.setup(23, You do not have permission to view the full content of this post. Log in or register now.)
# Sensor
GPIO.setup(22, You do not have permission to view the full content of this post. Log in or register now.)
# Reader
GPIO.setup(6, You do not have permission to view the full content of this post. Log in or register now.)
print('Please swipe your card')
try:
while True:
button=GPIO.input(23)
sensor=GPIO.input(22)
reader=GPIO.input(6)

if credit==1:
if button==1:
GPIo_Output(25, GPIO.LOW)
time.sleep(1)
if sensor==GPIO.LOW:
GPIo_Output(25, GPIO.HIGH)
time.sleep(1)


finally:
GPIO.cleanup()
 
Hello Prince Baylon,

It looks like you are trying to write some code for a Raspberry Pi using the RPi.GPIO library. From your code, it seems that you are setting up some GPIO pins for controlling a relay, a push button, a sensor, and a card reader.

Here are a few suggestions and corrections for your code:

1. Make sure you have installed the RPi.GPIO library on your Raspberry Pi. You can install it by running the following command in the terminal: sudo apt-get install rpi.gpio.

2. The GPIO.setup() function expects the second argument to be a constant representing the direction of the GPIO pin. In your code, you have used a URL instead of a constant. You should replace [URL='http://gpio.in/']GPIO.IN[/URL] with GPIO.IN for all the pin setups.

3. It seems like you are checking for the values of button, sensor, and reader, but you have not defined the credit variable. Make sure you define and initialize the credit variable before using it in the if credit==1 condition.

4. The indentation of the code after the while True loop is incorrect. It should be indented one level deeper to be part of the loop.

Here is the corrected code:

Python:
import RPi.GPIO as GPIO
import time

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

# Relay 1
GPIO.setup(25, GPIO.OUT)
# Push Button
GPIO.setup(23, GPIO.IN)
# Sensor
GPIO.setup(22, GPIO.IN)
# Reader
GPIO.setup(6, GPIO.IN)

print('Please swipe your card')

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

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

finally:
    GPIO.cleanup()

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

Similar threads

Back
Top