Skip to content
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

Added RapberryPi project #586

Merged
merged 1 commit into from
Oct 5, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Created by Akshar Singh
#IMPORTANT - CAN ONLY WORK ON RASPBERRY PI OPERATING SYSTEM
import RPi.GPIO as GPIO
from time import sleep

#GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD) #use phyical pin numbering

c = 0
#Light on
def lighton():
GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW)#spicifies the pin number to be the output pin
#initial value is low(OFF)
c=c+1
while True:
GPIO.output(8,GPIO.HIGH)

#Light off
def lightoff():
if(c==1):
GPIO.output(8,GPIO.LOW)

#Blinking
def lightblink():
GPIO.setup(8,GPIO.OUT,initial=GPIO.LOW)
while True: #running forever
GPIO.output(8,GPIO.HIGH) #Turn on
sleep(1)
GPIO.output(8,GPIO.LOW) #Turn off
sleep(1)
#light is on for 1 sec and then gets off for 1 second

#Control Brightness
def brightness():
#GPIO.PWM(PIN NUMBER,MAX BRIGHTNESS)
GPIO.setup(8,GPIO.OUT,initial=GPIO.HIGH)
P = GPIO.PWM(8,100) #PWM - Pulse width modulation(reducing avg power delivered by an electrical signal)
P.start(0) #LED starts with 0 % brightness

while True:
#LED's brightness is increasing gradually
for i in range(100):
P.start(i)
sleep(0.5)
#LED's brightness is decreasing gradually
for i in range(100):
P.start(100-i)
sleep(0.5)