Saturday, 29 December 2018

Project : Control LED Using Raspberry Pi 3 B+ |

Project : Control LED Using Raspberry Pi 3 B+ | Python Program

YouTube URLs:

Project : Control LED Using Raspberry Pi 3 B+




program: Control LED Using Raspberry Pi 3 B+

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

RedLEDPin = 11 

def setup():
GPIO.setmode(GPIO.BOARD)     
GPIO.setup(RedLEDPin, GPIO.OUT) 
GPIO.output(RedLEDPin, GPIO.LOW)

def lightson():
while True:
GPIO.output(RedLEDPin, GPIO.HIGH)
time.sleep(2)
GPIO.output(RedLEDPin, GPIO.LOW)
time.sleep(2)
def stop():
GPIO.output(RedLEDPin, GPIO.LOW)   
GPIO.cleanup()                   

if (__name__ == '__main__'):   
setup()
try:
#
lightson()
except KeyboardInterrupt:
stop()



Project : LEDs Blink using Raspberry Pi | Python Programming

Project : LED Blink using Raspberry Pi | Python Programming 

YouTube URLs

Project : LED Blink using Raspberry Pi




Program: Project : LED Blink using Raspberry Pi | Python Programming

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

RedledPin = 11 
BlueledPin = 12
GreenledPin = 13
YellowledPin = 16


def setup():
GPIO.setmode(GPIO.BOARD)     
GPIO.setup(RedledPin, GPIO.OUT)
GPIO.output(RedledPin, GPIO.LOW)
GPIO.setup(BlueledPin, GPIO.OUT)
GPIO.output(BlueledPin, GPIO.LOW)
GPIO.setup(GreenledPin, GPIO.OUT)
GPIO.output(GreenledPin, GPIO.LOW)
GPIO.setup(YellowledPin, GPIO.OUT)
GPIO.output(YellowledPin, GPIO.LOW)

def lightsOn():
GPIO.output(RedledPin, GPIO.HIGH)
GPIO.output(BlueledPin, GPIO.HIGH)
GPIO.output(GreenledPin, GPIO.HIGH)
GPIO.output(YellowledPin, GPIO.HIGH)

def stop():
GPIO.output(RedledPin, GPIO.LOW) 
GPIO.output(BlueledPin, GPIO.LOW)
GPIO.output(GreenledPin, GPIO.LOW)
GPIO.output(YellowledPin, GPIO.LOW)
GPIO.cleanup()                   

if (__name__ == '__main__'):     # Main Program Start From Here
setup()
try:
lightsOn()
except KeyboardInterrupt:  # When 'Ctrl+C' is pressed or stopped program
stop()



Odd Or Even Program LED output using Raspberry Pi | Python Program

Odd Or Even Program LED output using Raspberry Pi | Python Programming


YouTube URLs:

Odd Or Even Program LED Output using Raspberry Pi



Program: OddOrEven.py

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time
RedLEDPin = 11 
GreenLEDPin = 22

def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RedLEDPin, GPIO.OUT)
GPIO.output(RedLEDPin, GPIO.LOW)
GPIO.setup(GreenLEDPin, GPIO.OUT)
GPIO.output(GreenLEDPin, GPIO.LOW)

def FindOddEven():
        while True:
            player = int(input("Player Choise..."))
            remainder = player % 2
            if(remainder == 0):
                print("Even LED on")
                GPIO.output(RedLEDPin, GPIO.HIGH)
                time.sleep(3)
                GPIO.output(RedLEDPin, GPIO.LOW)
            else:
                print("Odd LED on")
                GPIO.output(GreenLEDPin, GPIO.HIGH)
                time.sleep(2)
                GPIO.output(GreenLEDPin, GPIO.LOW)

def destroy():
GPIO.output(RedLEDPin, GPIO.LOW)
GPIO.output(GreenLEDPin, GPIO.LOW)
GPIO.cleanup()

if (__name__ == '__main__'):     #Main Program Starting From Here
setup()
try:
FindOddEven()
except KeyboardInterrupt:
destroy()