Digital Electronics (USIU)
Contents
Digital Electronics
Study of Logic Gates – AND, OR, NOT
In-Lab Exercise 1: Realizing a AND gate
- Step 1
- Step 2 load the python code into your favorite code editor and copy paste the following code and save it as buttonpressed.py
In our case we used the command line and opened the nano editor and added the following code
#nano buttonpressed.py
import RPi.GPIO as GPIO
import time
#import random
GPIO.setmode(GPIO.BCM)
GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)
while True:
input = GPIO.input(6)
if input == False:
print ("Button Pressed")
time.sleep(0.2)
In-Lab Exercise 2: Realizing a OR gate
- Step 1 Connect the Circuit as shown in the image below
- Step 2 load the python code into your favorite code editor and copy paste the following code and save it as LightsOn.py
- In our case we used the command line and opened the nano editor and added the following code
#nano LightsOn.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
led = 4
GPIO.setup(led, GPIO.OUT)
GPIO.output(led,1)
time.sleep(0.5)
GPIO.output(led, 0)
time.sleep(0.05)
In-Lab Exercise 3: Realizing a NOT gate
- Step 1 Connect the Circuit as shown in the image below
- Step 2 load the python code into your favorite code editor and copy paste the following code and save it as SwitchLightsOn.py
In our case we used the command line and opened the nano editor and added the following code
#nano SwitchLightsOn.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(6,GPIO.IN,pull_up_down = GPIO.PUD_UP)
led = 4
GPIO.setup(led, GPIO.OUT)
while True:
input = GPIO.input(6)
if input == False:
print ("Button Pressed")
time.sleep(0.2)
GPIO.output(led,1)
time.sleep(0.5)
GPIO.output(led, 0)
time.sleep(0.05)