Skip to content

Suggestions to Adeept_RFID_LearningKit_for_RPi #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 02_activeBuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import RPi.GPIO as GPIO
import time

BeepPin = 11 # pin11
BeepPin = 12 # pin12

def setup():
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(BeepPin, GPIO.OUT) # Set pin mode as output
GPIO.output(BeepPin, GPIO.HIGH) # Set pin to high(+3.3V) to off the beep
GPIO.output(BeepPin, GPIO.LOW) # Set pin to high(+3.3V) to off the beep

def loop():
while True:
GPIO.output(BeepPin, GPIO.LOW)
GPIO.output(BeepPin, GPIO.HIGH) # Beep On
time.sleep(0.1)
GPIO.output(BeepPin, GPIO.HIGH)
GPIO.output(BeepPin, GPIO.LOW) # Beep Off
time.sleep(0.1)

def destroy():
GPIO.output(BeepPin, GPIO.HIGH) # beep off
GPIO.output(BeepPin, GPIO.LOW) # Beep Off
GPIO.cleanup() # Release resource

if __name__ == '__main__': # Program start from here
Expand Down
12 changes: 6 additions & 6 deletions 03_passiveBuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
import RPi.GPIO as GPIO
import time

BZRPin = 11
BZRPin = 12 # Set Pin Phyiscal Pin 12

GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
GPIO.setup(BZRPin, GPIO.OUT) # Set pin mode as output
GPIO.output(BZRPin, GPIO.LOW)
GPIO.output(BZRPin, GPIO.LOW) # Set Buzzer to Off

p = GPIO.PWM(BZRPin, 50) # init frequency: 50HZ
p.start(50) # Duty cycle: 50%

try:
while True:
for f in range(100, 2000, 100):
for f in range(100, 2000, 100): # Implements a loop increasing frequency
p.ChangeFrequency(f)
time.sleep(0.2)
for f in range(2000, 100, -100):
for f in range(2000, 100, -100): # Implememnts a loop decreasing frequency
p.ChangeFrequency(f)
time.sleep(0.2)
except KeyboardInterrupt:
except KeyboardInterrupt: # When a keyboard interrupt is detected, stop the while loop and cleanup
p.stop()
GPIO.cleanup()
GPIO.cleanup() # Release GPIO resources
4 changes: 2 additions & 2 deletions 04_tiltSwitch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python
import RPi.GPIO as GPIO

TiltPin = 11
LedPin = 12
TiltPin = 12 # Set Physical Pin number
LedPin = 11 # Set Phyiscal Pin number

Led_status = 1

Expand Down
4 changes: 2 additions & 2 deletions 06_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import RPi.GPIO as GPIO
import time

RelayPin = 11 # pin11
RelayPin = 12 # Set Pin to Physical Pin 12

def setup():
GPIO.setmode(GPIO.BOARD) # Numbers pins by physical location
Expand All @@ -11,7 +11,7 @@ def setup():

def loop():
while True:
print '...clsoe'
print '...close'
GPIO.output(RelayPin, GPIO.LOW)
time.sleep(0.5)
print 'open...'
Expand Down
3 changes: 1 addition & 2 deletions 07_flowingLed.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import RPi.GPIO as GPIO
import time

pins = [11, 12, 13, 15, 16, 18, 22, 7]

pins = [7, 22, 18, 16, 15, 13, 12, 11]
def setup():
GPIO.setmode(GPIO.BOARD) # Numbers GPIOs by physical location
for pin in pins:
Expand Down
172 changes: 86 additions & 86 deletions 13_matrixKeyboard.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
class keypad():
# CONSTANTS
KEYPAD = [
[1,2,3,"A"],
[4,5,6,"B"],
[7,8,9,"C"],
["*",0,"#","D"]
]
ROW = [11,12,13,15]
COLUMN = [16,18,22,7]
def __init__(self):
GPIO.setmode(GPIO.BOARD)
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 2.
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 2 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)
if __name__ == '__main__':
# Initialize the keypad class
kp = keypad()
# Loop while waiting for a keypress
while True:
digit = None
while digit == None:
digit = kp.getKey()
# Print the result
print digit
time.sleep(0.5)
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

class keypad():
# CONSTANTS
KEYPAD = [
[1, 2, 3, "A"],
[4, 5, 6, "B"],
[7, 8, 9, "C"],
["*", 0, "#", "D"]
]

ROW = [11, 12, 13, 15]
COLUMN = [16, 18, 22, 7]

def __init__(self):
GPIO.setmode(GPIO.BOARD)

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 2 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)

if __name__ == '__main__':
# Initialize the keypad class
kp = keypad()
# Loop while waiting for a keypress
while True:
digit = None
while digit == None:
digit = kp.getKey()
# Print the result
print digit
time.sleep(0.5)