Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import RPi.GPIO as GPIO
- GPIO.setwarnings(False)
- class keypad():
- def __init__(self,Row,Column):
- GPIO.setmode(GPIO.BCM)
- self.KEYPAD = [
- [1,2,3,"A"],
- [4,5,6,"B"],
- [7,8,9,"C"],
- ["*",0,"#","D"]
- ]
- self.ROW = Row
- self.COLUMN = Column
- def getKey(self):
- # Set all columns as output low
- for j in range(len(self.COLUMN)):
- GPIO.setup(self.COLUMN[j], GPIO.OUT)
- GPIO.output(self.COLUMN[j], GPIO.LOW)
- # Set all rows as input
- for i in range(len(self.ROW)):
- GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
- # Scan rows for pushed key/button
- # A valid key press should set "rowVal" between 0 and 3.
- rowVal = -1
- for i in range(len(self.ROW)):
- tmpRead = GPIO.input(self.ROW[i])
- if tmpRead == 0:
- rowVal = i
- # if rowVal is not 0 thru 3 then no button was pressed and we can exit
- if rowVal <0 or rowVal >3:
- self.exit()
- return
- # Convert columns to input
- for j in range(len(self.COLUMN)):
- GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- # Switch the i-th row found from scan to output
- GPIO.setup(self.ROW[rowVal], GPIO.OUT)
- GPIO.output(self.ROW[rowVal], GPIO.HIGH)
- # Scan columns for still-pushed key/button
- # A valid key press should set "colVal" between 0 and 3.
- colVal = -1
- for j in range(len(self.COLUMN)):
- tmpRead = GPIO.input(self.COLUMN[j])
- if tmpRead == 1:
- colVal=j
- # if colVal is not 0 thru 3 then no button was pressed and we can exit
- if colVal <0 or colVal >3:
- self.exit()
- return
- # Return the value of the key pressed
- self.exit()
- return self.KEYPAD[rowVal][colVal]
- def exit(self):
- # Reinitialize all rows and columns as input at exit
- for i in range(len(self.ROW)):
- GPIO.setup(self.ROW[i], GPIO.IN, pull_up_down=GPIO.PUD_UP)
- for j in range(len(self.COLUMN)):
- GPIO.setup(self.COLUMN[j], GPIO.IN, pull_up_down=GPIO.PUD_UP)
- kp = keypad(Row=[21,20,16,7],Column=[26,19,13,6])
- st_press=0
- digit_str=''
- x=0
- import RPi.GPIO as GPIO
- import time
- from datetime import datetime
- GPIO.setwarnings(False)
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(24,GPIO.OUT)
- blink = GPIO.PWM(24,500)
- blink.start(0)
- import time
- from neopixel import *
- import time
- import Adafruit_SSD1306
- from PIL import Image,ImageDraw,ImageFont
- # Raspberry Pi pin configuration:
- RST = 1
- # 128x64 display with hardware I2C:
- disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
- # Note you can change the I2C address by passing an i2c_address parameter like:
- # disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST, i2c_address=0x3C)
- # Initialize library.
- disp.begin()
- # Clear display.
- disp.clear()
- # LED strip configuration:
- LED_COUNT = 1 # Number of LED pixels.
- LED_PIN = 12 # GPIO pin connected to the pixels (must support PWM!).
- LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
- LED_DMA = 5 # DMA channel to use for generating signal (try 5)
- LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
- LED_INVERT = False
- strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
- # Intialize the library (must be called once before other functions).
- strip.begin()
- while 1:
- # Loop while waiting for a keypress
- digit = None
- digit = kp.getKey()
- if digit == None:
- st_press=1
- blink.ChangeDutyCycle(0)
- strip.setPixelColor(0, Color(0, 0,0))
- strip.show()
- width = disp.width
- height = disp.height
- image = Image.new('1', (width, height))
- draw = ImageDraw.Draw(image)
- font = ImageFont.truetype('VCR_OSD_MONO_1.001.ttf',22)
- draw.text((0,0), ' ',font=font, fill=1)
- draw.text((0,20), ' ',font=font, fill=1)
- draw.text((0,40), ' ',font=font, fill=1)
- disp.image(image)
- disp.display()
- else:
- if st_press:
- blink.ChangeDutyCycle(50)
- # Print the result
- x+=1
- digit_str+=str(digit)
- print (digit_str,end='\r')
- st_press=0
- time.sleep(0.3)
- blink.ChangeDutyCycle(0)
- if x==4:
- if digit_str=="4096":
- width = disp.width
- height = disp.height
- image = Image.new('1', (width, height))
- draw = ImageDraw.Draw(image)
- font = ImageFont.truetype('VCR_OSD_MONO_1.001.ttf',22)
- draw.text((0,0), 'Ironman',font=font, fill=1)
- disp.image(image)
- disp.display()
- strip.setPixelColor(0, Color(0, 0, 255))# Red
- strip.show()
- digit_str=''
- x=0
- time.sleep(1)
- elif digit_str=="2048":
- width = disp.width
- height = disp.height
- image = Image.new('1', (width, height))
- draw = ImageDraw.Draw(image)
- font = ImageFont.truetype('VCR_OSD_MONO_1.001.ttf',22)
- draw.text((0,0), 'Antman',font=font, fill=1)
- disp.image(image)
- disp.display()
- strip.setPixelColor(0, Color(0,255,0))# Red
- strip.show()
- digit_str=''
- x=0
- time.sleep(1)
- else:
- width = disp.width
- height = disp.height
- image = Image.new('1', (width, height))
- draw = ImageDraw.Draw(image)
- font = ImageFont.truetype('VCR_OSD_MONO_1.001.ttf',18)
- draw.text((0,0), 'Access denind',font=font, fill=1)
- disp.image(image)
- disp.display()
- strip.setPixelColor(0, Color(255,0,0))# Red
- strip.show()
- digit_str=''
- x=0
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment