Proteus_Raspberrypi
RaspberryPi LED Blinking:
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
LED_Red =7
LED_Yellow =11
GPIO.setup(LED_Red, GPIO.OUT)
GPIO.setup(LED_Yellow, GPIO.OUT)
while 1:
GPIO.output(LED_Red, True)
time.sleep(1)
GPIO.output(LED_Yellow, True)
time.sleep(1)
GPIO.output(LED_Red, False)
time.sleep(1)
GPIO.output(LED_Yellow, False)
time.sleep(1)
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
LED_Red =7
LED_Yellow =11
GPIO.setup(LED_Red, GPIO.OUT)
GPIO.setup(LED_Yellow, GPIO.OUT)
while 1:
GPIO.output(LED_Red, True)
time.sleep(1)
GPIO.output(LED_Yellow, True)
time.sleep(1)
GPIO.output(LED_Red, False)
time.sleep(1)
GPIO.output(LED_Yellow, False)
time.sleep(1)
RaspberryPi Push Button and LED control:
#!/usr/bin/env python3
import RPi.GPIO as GPIO
import time
led_on = False
count = 0
def setupGPIO():
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def flashLED(count):
for i in range(count):
GPIO.output(18, GPIO.HIGH)
time.sleep(.2)
GPIO.output(18, GPIO.LOW)
time.sleep(.2)
def switch(ev=None):
global led_on, count
led_on = not led_on
count += 1
if led_on == True:
print("Turning on\tcount: " + str(count))
GPIO.output(18, GPIO.HIGH)
else:
print("Turning off\tcount: " + str(count))
GPIO.output(18, GPIO.LOW)
def detectButtonPress():
GPIO.add_event_detect(23, GPIO.FALLING, callback=switch, bouncetime=300)
def waitForEvents():
while True:
time.sleep(1)
# # # # # MAIN # # # # #
def main():
print("# # # LED Program # # #")
print("LED:\tpin 18")
print("Button:\tpin 23")
setupGPIO()
flashLED(5)
detectButtonPress()
waitForEvents()
if __name__ == "__main__":
main()
#ref purpose (default code in source code of RaspberryPi)
# !/usr/bin/env python3
#!/usr/bin/env python3
# Main.py file generated by New Project wizard
# Created: Wed Feb 28 2024
# Processor: RPI3
# Compiler: Python 3 (Proteus)
# Modules
from goto import *
import time
import var
import pio
import resource
# Peripheral Configuration Code (do not edit)
#---CONFIG_BEGIN---
import cpu
import FileStore
import VFP
def peripheral_setup () :
# Peripheral Constructors
pio.cpu=cpu.CPU ()
pio.storage=FileStore.FileStore ()
pio.server=VFP.VfpServer ()
pio.storage.begin ()
pio.server.begin (0)
# Install interrupt handlers
def peripheral_loop () :
pio.server.poll ()
#---CONFIG_END---
# Main function
def main () :
# Setup
peripheral_setup()
# Infinite loop
while 1 :
peripheral_loop()
pass
# Command line execution
if __name__ == '__main__' :
main()