Skip to content

Commit

Permalink
Interrupts and internal rezistors
Browse files Browse the repository at this point in the history
  • Loading branch information
Eivel committed Oct 18, 2014
1 parent 93b698c commit 98437db
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 0 deletions.
20 changes: 20 additions & 0 deletions buzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__author__ = 'Wojciech'
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.OUT)

GPIO.output(18,1)
time.sleep(.1)
GPIO.output(18,0)
time.sleep(.1)
GPIO.output(18,1)
time.sleep(.1)
GPIO.output(18,0)
time.sleep(.1)
GPIO.output(18,1)
time.sleep(.1)
GPIO.output(18,0)

GPIO.cleanup()
20 changes: 20 additions & 0 deletions callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
__author__ = 'Wojciech'
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(18,GPIO.OUT)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def button_pushed(channel):
GPIO.output(18,1)

def button_released(channel):
GPIO.output(18,0)

GPIO.add_event_detect(21, GPIO.RISING, callback=button_pushed, bouncetime=300)
GPIO.add_event_detect(16, GPIO.FALLING, callback=button_released, bouncetime=300)

time.sleep(10)
GPIO.cleanup()
10 changes: 10 additions & 0 deletions led16_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__author__ = 'Wojciech'
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

while True:
if(GPIO.input(16) == 1):
print("Button pressed")
31 changes: 31 additions & 0 deletions led_callback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import time
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

GPIO.setwarnings(False)

GPIO.setup(17, GPIO.OUT)
GPIO.setup(16, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

is_high = False

try:
while True:
if(GPIO.input(16) == True):
print("Button pressed")
os.system('date')
print(GPIO.input(16))
if(is_high):
GPIO.output(17,GPIO.LOW)
is_high=False
else:
GPIO.output(17,GPIO.HIGH)
is_high=True
time.sleep(1)

else:
os.system('clear')
print("Waiting for you to press a button")
except KeyboardInterrupt:
GPIO.cleanup()
2 changes: 2 additions & 0 deletions python_sudo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo python $@
34 changes: 34 additions & 0 deletions rgb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import RPi.GPIO as GPIO
import time, math

GPIO.setmode(GPIO.BCM)
GPIO.setup(27, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)

r_int = 100
g_int = 100
b_int = 100

r = GPIO.PWM(27, 60)
g = GPIO.PWM(18, 60)
b = GPIO.PWM(17, 60)

r.start(r_int)
g.start(g_int)
b.start(b_int)

sa = 0

for x in range(0, 1000):
r_int = 90 * (math.sin(sa) + 1) / 2 + 10
g_int = 80 * (math.sin(sa - 3.141592) + 1) / 2 + 20
b_int = 100 * (math.sin(sa - 1.570796) + 1) / 2
sa += 0.04
r.ChangeDutyCycle(r_int)
g.ChangeDutyCycle(g_int)
b.ChangeDutyCycle(b_int)
time.sleep(0.05)
time.sleep(2)

GPIO.cleanup()

0 comments on commit 98437db

Please sign in to comment.