diff --git a/02_activeBuzzer.py b/02_activeBuzzer.py index f4b4fee..fd228e9 100755 --- a/02_activeBuzzer.py +++ b/02_activeBuzzer.py @@ -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 diff --git a/03_passiveBuzzer.py b/03_passiveBuzzer.py index 9fd7b3a..4e86df1 100755 --- a/03_passiveBuzzer.py +++ b/03_passiveBuzzer.py @@ -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 diff --git a/04_tiltSwitch.py b/04_tiltSwitch.py index 3330dbf..93f187f 100755 --- a/04_tiltSwitch.py +++ b/04_tiltSwitch.py @@ -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 diff --git a/06_relay.py b/06_relay.py index 5741184..7311edd 100755 --- a/06_relay.py +++ b/06_relay.py @@ -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 @@ -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...' diff --git a/07_flowingLed.py b/07_flowingLed.py index 6e06242..e9dea63 100755 --- a/07_flowingLed.py +++ b/07_flowingLed.py @@ -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: diff --git a/13_matrixKeyboard.py b/13_matrixKeyboard.py index 29c57ed..e455f32 100755 --- a/13_matrixKeyboard.py +++ b/13_matrixKeyboard.py @@ -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)