# Lab 4: Multiple Inputs

The questions below are due on Sunday July 22, 2018; 11:59:00 AM.

You are not logged in.

Music for this Lab

## Goals:

In this lab we'll interface with a more complex input device (a grid switch) by studying how it works and then writing some code to interface to it.

### 0.1) Multiple Inputs

We'll be using the switch grid below for our lab project today. It consists of 16 buttons that form an interconnected grid like that shown below. When a button is pressed it connects a specific row to a specific column. Notice that each button will result in a unique row/column connection and through this (by checking the connections) we can deduce electrically which button is being pushed using only 8 wires. If we were to do this using the earlier switches we were using, we'd need ~32 wires which would suck.

The switch pads look like the following...the left four electrodes are one dimension in order and the right four switches are the other dimension (you'll need to figure out which is which).

The standard approach to working with switch arrays of the type shown here is to connect four of the wires (either all four rows or all four column wires, but not both) to outputs you control, and then use the other four wires (either all four columns or all four rows, respectively) as inputs. Then set up an electrical pattern on the four wires that the Raspberry Pi controls (outputs), and see if any information can be gleaned from the four wires that are inputs to the Raspberry Pi.

In order to think about how to approach this, re-imagine the problem as dealing with light and each row/column was a light tunnel where a pushed switch connects it. If you didn't know what was being done to the keypad, but you could use your eyes to look down certain light tunnels and shine a flashlight down other light tunnels, how would you be able to deduce what buttons, if any, are being pushed? Think about this. Once you have an idea, map that idea to the electrical domain where we can turn ON or OFF wires and listen to other wires. Chat with a staff member about this.

We've provided some simple starting code below to get you going. Yuur job is to fill in the code below to have Python print out what button is being pushed. (You don't need to worry about when more than one button is being pushed at any one time) This will take some time and thinking! First think about how you can give each row a uniquely identifying signal (one at at time)! Then think about how to read each column/input.

Generate code so that it will print (correctly) the symbol being pressed on the keypad.

Try Now:

If you set all four rows to be a high voltage, and you sequentially measured the voltage on all four column wires, what can you conclude if you measured low voltages on columns 1, 2, and 4 and a high voltage on column 3?

Try Now:

If you set the last three rows to be a low voltage and first row to be a high voltage, and you sequentially measured the values on all four column wires, what information could you determine?

Try Now:

If you set rows 1, 3, and 4 to be a low voltage and two row to be a high voltage, and you sequentially measured the values on all four column wires, what information could you determine? What would it mean if the four readings on the column (in order) were Low, High, Low, Low?

import RPi.GPIO as GPIO  #import library to use input/output pins
import pygame
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
inputs = [5,22,27,17]
outputs = [26,19,13,6]

#set the four input pins as inputs!
for i in inputs:
GPIO.setup(i,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#set the four output pins as outputs! and start them all low!
for o in outputs:
GPIO.setup(o,GPIO.OUT)
GPIO.output(o,0)

# A nested Python list for your use:

symbols = [['1','2','3','A'],
['4','5','6','B'],
['7','8','9','C'],
['*','0','#','D']]

last_symbol = ''

def measure_switches():
for i in inputs
#You need to turn on each row and then check which
#columns (if any) are connected to it. Look up the symbol
# and then finally print it!

while True:
output = measure_switches()
print(output)
time.sleep(0.05)


Demonstrate your working system in a video. Be sure to show a mix of buttons and the resultant letters and numbers appearing.

Enter the url for the video