Created
March 31, 2019 22:29
-
-
Save sumanssaurabh/be16fc07d34236bb2b28bebe5fda72d8 to your computer and use it in GitHub Desktop.
HT12E
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python v3.4.2 console based script | |
# Set Raspberry Pi GPIO ports Low depending on user input | |
# User enters number between 0 and 15, GPIO ports 22, 23, 24 & 25 | |
# are set as BCD representations of the decimal input. | |
# GPIO ports are weighted 0, 2, 4, 8 [GPIO 22, 23, 24, 25] | |
# Number 99 entered quits the script | |
# GPIO ports connect to AD8-11 ports on HT12E encoder chip | |
# user input is BCD coded & used to set AD8-11 ports | |
# GPIO port 17 is used to send trigger pulse to activate the HT12E for 1 complete cycle | |
import RPi.GPIO as GPIO # import GPIO module | |
import time | |
GPIO.setwarnings(False) # disable warning messages | |
GPIO.setmode(GPIO.BCM) # use chip GPIO pin numbers | |
GPIO.setup(17, GPIO.OUT) | |
GPIO.output(17, GPIO.LOW) | |
GPIO.setup(22, GPIO.OUT) | |
GPIO.output(22, GPIO.HIGH) | |
GPIO.setup(23, GPIO.OUT) | |
GPIO.output(23, GPIO.HIGH) | |
GPIO.setup(24, GPIO.OUT) | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.setup(25, GPIO.OUT) | |
GPIO.output(25, GPIO.HIGH) | |
def One(): | |
GPIO.output(22, GPIO.LOW) | |
def Two(): | |
GPIO.output(23, GPIO.LOW) | |
def Four(): | |
GPIO.output(24, GPIO.LOW) | |
def Eight(): | |
GPIO.output(25, GPIO.LOW) | |
def ClearAll(): | |
GPIO.output(22, GPIO.HIGH) | |
GPIO.output(23, GPIO.HIGH) | |
GPIO.output(24, GPIO.HIGH) | |
GPIO.output(25, GPIO.HIGH) | |
def Trigger(): | |
GPIO.output(17, GPIO.HIGH) | |
time.sleep(0.005) | |
GPIO.output(17, GPIO.LOW) | |
try: | |
while True: | |
print ("Setting GPIO ports Decimal to BCD") | |
print ("Enter number between 0 and 15 [99 quits]") | |
print ("Warning! supplied parameters are not validated") | |
decimal = input(">_ ") # get number as a string | |
dec_number = int(decimal) # convert string to integer | |
if dec_number != 99: | |
ClearAll() # set A8-11 ports to '0000' | |
Trigger() # send trigger pulse | |
time.sleep(0.1) | |
if dec_number == 0: | |
ClearAll() | |
Trigger() | |
if dec_number == 1: | |
One() | |
Trigger() | |
if dec_number == 2: | |
Two() | |
Trigger() | |
if dec_number == 3: | |
One() | |
Two() | |
Trigger() | |
if dec_number == 4: | |
Four() | |
Trigger() | |
if dec_number == 5: | |
One() | |
Four() | |
Trigger() | |
if dec_number == 6: | |
Two() | |
Four() | |
Trigger() | |
if dec_number == 7: | |
One() | |
Two() | |
Four() | |
Trigger() | |
if dec_number == 8: | |
Eight() | |
Trigger() | |
if dec_number == 9: | |
One() | |
Eight() | |
Trigger() | |
if dec_number == 10: | |
Two() | |
Eight() | |
Trigger() | |
if dec_number == 11: | |
One() | |
Two() | |
Eight() | |
Trigger() | |
if dec_number == 12: | |
Four() | |
Eight() | |
Trigger() | |
if dec_number == 13: | |
One() | |
Four() | |
Eight() | |
Trigger() | |
if dec_number == 14: | |
Two() | |
Four() | |
Eight() | |
Trigger() | |
if dec_number == 15: | |
One() | |
Two() | |
Four() | |
Eight() | |
Trigger() | |
else: # user exit | |
print ("Exiting..") | |
GPIO.cleanup() | |
break | |
except KeyboardInterrupt: # catch the Ctrl-C | |
print ("Exit..") | |
except: # catch other errors | |
print ("Error..Exiting") | |
finally: # clean up on exit | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment