NUM_MAPS =[[1, 1, 1, 1, 1, 1, 0], #0 [0, 1, 1, 0, 0, 0, 0], #1 [1, 1, 0, 1, 1, 0, 1], #2 [1, 1, 1, 1, 0, 0, 1], #3 [0, 1, 1, 0, 0, 1, 1], #4 [1, 0, 1, 1, 0, 1, 1], #5 [1, 0, 1, 1, 1, 1, 1], #6 [1, 1, 1, 0, 0, 0, 0], #7 [1, 1, 1, 1, 1, 1, 1], #8 [1, 1, 1, 1, 0, 1, 1]] #9 SEGMENT_PINS = [2,3,4,17,27,22,10] import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(SEGMENT_PINS,GPIO.OUT) def displayDigit(digit): if((digit < 0) or (digit > 9)): return for i in range(7): GPIO.output(SEGMENT_PINS[i],NUM_MAPS[digit][i] ) time.sleep(0.0005) GPIO.output(SEGMENT_PINS[i],GPIO.LOW) num = 0; counter = 0; while (1): display4Digit(num); counter += 1 if(counter == 200): counter = 0 num += 1 if(num > 9): num = 0; import RPi.GPIO as GPIO import time KEY_MAPS = [[ '1', '2', '3', '4'], [ '5', '6', '7', '8'], [ '9','10','11','12'], ['13','14','15','16']]; COL_PINS = [0,1,2,3]; ROW_PINS = [4,5,6,7]; GPIO.setmode(GPIO.BCM) GPIO.setup(COL_PINS,GPIO.OUT) GPIO.setup(ROW_PINS,GPIO.IN) def getKey(): key = '\0'; for i in range(4): GPIO.output(COL_PINS[i],GPIO.HIGH) for j in range(4): if(GPIO.input(ROW_PINS[j]) == 1): key = KEY_MAPS[j][i]; time.sleep(0.250); GPIO.output(COL_PINS[i],GPIO.LOW) return key; while(1): key = getKey()