Saturday, 29 December 2018

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


No comments:

Post a Comment