Skip to content

Instantly share code, notes, and snippets.

@aula9
Created April 14, 2021 04:22
Show Gist options
  • Save aula9/4306ce529d1f40d91824ec21e410af17 to your computer and use it in GitHub Desktop.
Save aula9/4306ce529d1f40d91824ec21e410af17 to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
import time
import serial
L1 = 25
L2 = 8
L3 = 7
L4 = 1
C1 = 16
C2 = 20
C3 = 21
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(L1, GPIO.OUT)
GPIO.setup(L2, GPIO.OUT)
GPIO.setup(L3, GPIO.OUT)
GPIO.setup(L4, GPIO.OUT)
# Make sure to configure the input pins to use the internal pull-down resistors
GPIO.setup(C1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(C3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
ch1= ["1","2","3"]
ch2= ["4","5","6"]
ch3= ["7","8","9"]
ch4= ["*","0","#"]
p=0
ser = serial.Serial(
port='/dev/ttyS0',
baudrate = 921600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
print(ser.name)
ser.write ('\r'.encode())
time.sleep(4)
ser.write ('ping'.encode())
ser.write ('\r'.encode())
x=ser.read(3000)
time.sleep(10)
print(x)
def readLine(line, characters):
global p
GPIO.output(line, GPIO.HIGH)
if(GPIO.input(C1) == 1):
print(characters[0])
p=characters[0]
if(GPIO.input(C2) == 1):
print(characters[1])
p=characters[1]
if(GPIO.input(C3) == 1):
print(characters[2])
p=characters[2]
GPIO.output(line, GPIO.LOW)
return p
try:
while True:
readLine(L1, ch1)
if(p =="1"):
print("red")
ser.write ('Color red 90)'.encode())
ser.write ('\r'.encode())
elif(p=="2"):
print("blue")
ser.write ('Color blue 90)'.encode())
ser.write ('\r'.encode())
elif(p=="3"):
print("green")
ser.write ('Color green 90)'.encode())
ser.write ('\r'.encode())
readLine(L2, ch2)
if(p =="4"):
print("yellow")
ser.write ('Color yellow 90)'.encode())
ser.write ('\r'.encode())
elif(p=="5"):
print("cyan")
ser.write ('Color cyan 90)'.encode())
ser.write ('\r'.encode())
elif(p=="6"):
print("magenta")
ser.write ('Color magenta 90)'.encode())
ser.write ('\r'.encode())
readLine(L3, ch3)
if(p =="7"):
print("white")
ser.write ('on 90)'.encode())
ser.write ('\r'.encode())
elif(p=="8"):
print("black")
ser.write ('off'.encode())
ser.write ('\r'.encode())
elif(p=="9"):
print("all")
ser.write ('Sweep fine 3000 3'.encode())
ser.write ('\r'.encode())
readLine(L4, ch4)
time.sleep(0.1)
except KeyboardInterrupt:
print("\nApplication stopped!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment