This blog is a record of what I do, what I think and what I read. If you are interested to know about my professional experience, you can refer to the other blog of mine. http://admi2camac.blogspot.com/
Friday, 27 January 2023
TRL-Exercise3m
#Library
from gpiozero import LED, Buzzer, Button
from time import sleep
from signal import pause
import tm1637
#Component setup
green_led = LED(18)
red_led = LED(14)
anti_spam_led = LED(7)
buzz = Buzzer(25)
button = Button(24)
display=tm1637.TM1637(20,16)
#Function
def activate():
if anti_spam_led.value == 1:
pass
else:
anti_spam_led.on()
greenman()
def greenman():
print('Button was pressed')
sleep(10)
red_led.off()
green_led.on()
sleep(10)
for counter in range(5,-1,-1):
green_led.blink(on_time=0.5, off_time=0.5, n=1)
buzz.blink(on_time=0.5, off_time=0.5, n=1)
display.set_values([' ',' ',' ',counter])
sleep(1)
green_led.off()
red_led.on()
anti_spam_led.off()
display.clear()
print('Waiting for Next Button Press')
#Algorithm
red_led.on()
anti_spam_led.off()
display.clear()
print('Program Started')
print('Waiting for button to be pressed')
button.when_pressed = activate
pause()
TRL-Exercise3g
#Library
from gpiozero import LED
from time import sleep
#Component setup
green_led = LED(18)
red_led = LED(14)
#Algorith
red_led.on()
sleep(10)
red_led.off()
green_led.on()
sleep(10)
green_led.blink(on_time=0.5, off_time=0.5, n=5)
sleep(5)
green_led.off()
red_led.on()
2RGB led running on Raspberry Pi Pico
from picozero import RGBLED
from time import sleep
rgb = RGBLED(red = 1, green = 2, blue = 3)
rgb.blink() # red for 1 second, green for 1 second, blue for 1 second
print("Blinking with all colors") # Runs immediately
sleep(3)
rgb.off()
# blink purple 2 seconds, off 0.5 seconds
rgb.blink(on_times=(2, 0.5), colors=((255, 0, 255), (0, 0, 0)), wait=True, n=3)
print("Finished blinking purple") # Runs after 3 repeats
sleep(3)
rgb.off()
# blink red 1 second, green 0.5 seconds, blue 0.25 seconds
rgb.blink((1, 0.5, 0.25), colors=((255, 0, 0), (0, 255, 0), (0, 0, 255)), wait=True, n=2)
print("Finished blinking different color different duration") # Runs after 2 blink repeats
sleep(3)
rgb.off()
for x in range(1, 4, 1):
rgb.color = (255, 0, 0)
sleep(0.5)
rgb.color = (0, 255, 0)
sleep(0.5)
rgb.color = (0, 0, 255)
sleep(0.5)
print("ON and OFF the 3 colors")
rgb.off()
rgb.pulse() # pulse red for 1 second, green for 1 second, blue for 1 second
print("Pulsing") # Runs immediately
sleep(3)
rgb.off()
# 2 second to fade from purple to off, 0.5 seconds to change from off to purple
rgb.pulse(fade_times=(2, 0.5), colors=((255, 0, 255), (0, 0, 0)), wait=True, n=3)
print("Finished pulsing") # Runs after 3 pulses
sleep(3)
rgb.off()
rgb.cycle() # Gradually colour cycle through colours between red and green, green and blue then blue and red
print("Cycle") # Runs immediately
sleep(3)
rgb.off()
# Colour cycle slower in the opposite direction
rgb.cycle(fade_times=3, colors=((0, 0, 255), (0, 255, 0), (255, 0, 0)), wait=True, n=2)
print("Cycle slowly 2 times")
sleep(3)
rgb.off()
#https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/8
1LED project on Raspberry Pi Pico
from picozero import LED
from time import sleep
yellow = LED(13)
yellow.on()
sleep(2)
yellow.off()
print("led ON")
#yellow.blink() # on for 1 second then off for one second
sleep(1)
yellow.blink(on_time=1, off_time=0.5, n=3, wait=True)
yellow.off()
print("Finished blinking") # Runs after 3 on/off blinks
sleep(1)
yellow.pulse() # take 1 second to brighten and 1 second to dim
sleep(3)
yellow.off()
print("Pulsing") # Runs immediately
sleep(1)
yellow.pulse(fade_in_time=3, fade_out_time=3, n=4, wait=True) # take 2 seconds to brighten and 1 second to dim
sleep(3)
yellow.off()
print("Finished pulsing") # Runs after 4 pulses
sleep(1)
yellow.blink(on_time=1, off_time=1, fade_in_time=3, fade_out_time=3) # On for 1 second, off for 1 second, fade between
sleep(3)
yellow.off()
print("Fancy") # Runs immediately
#https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/7
Subscribe to:
Posts (Atom)