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/
Saturday, 4 March 2023
Loads of leds (random display)
from picozero import LED
from time import sleep as zzz
from random import randint
#max of 16 LEDs if using picozero, due to PWM conflicts.
#Using 0 to 15 to make setup easier
num_leds = 8
overflow_num=2**num_leds
leds=[]
for i in range(0,num_leds):
leds.append(LED(i))
#shuffle LEDs
for j in range(num_leds):
i=randint(1,num_leds-1)
leds[j],leds[i]=leds[i],leds[j]
#reverse the order of i and j
try:
while True:
i=randint(0,overflow_num)
for j, led in enumerate(leds):
led.brightness=int(bin(i+overflow_num)[j+3])
zzz(3)
except KeyboardInterrupt:
for led in leds:
led.off()
print('Turn off LEDs and quit')
#https://www.youtube.com/watch?v=9MZGQmkeLAA
TTB05: Reading Analog Voltages Using a Potentiometer
import machine
from time import sleep
potPin = 28
myPot = machine.ADC(potPin)
while True:
potVal=myPot.read_u16()
#print('PotVal =',potVal)
#max=65535, min=1024, middle=65535-1024=64511
voltage = (3.3/64511)*potVal - (1024*3.3/64511)
#print('Voltage =',voltage)
percentage = (100/64511)*potVal-(1024*100/64511)
#print('Percentage = ',int(percentage))
print('PotVal =',potVal, 'Voltage =',voltage, 'Percentage = ',int(percentage))
sleep(1)
#https://www.youtube.com/watch?v=ODWwErH_iGA&list=PLGs0VKk2DiYz8js1SJog21cDhkBqyAhC5&index=5
TTB04a: Creating a Knight Rider LED display using a Pi Pico W
from machine import Pin
from time import sleep
for i in range (8,14):
Pin((i), Pin.OUT)
delay = 0.2
kr=[8,0,8,9,0,9,10,0,10,11,0,11,12,0,12,13,0,13]
def KITT():
for j in range(len(kr)):
if kr[j] == 0:
sleep(delay)
else:
Pin(kr[j]).toggle()
try:
while True:
KITT()
except KeyboardInterrupt:
for k in range(8,14):
Pin(k).value(0)
print('Keboard Interrupted, LEDs off')
#https://www.youtube.com/watch?v=cGgDzVtppaQ
TTB04: Create a Binary Counter Using the Pico W
from machine import Pin
from time import sleep
led1 = Pin(15, Pin.OUT)
led2 = Pin(14, Pin.OUT)
led3 = Pin(13, Pin.OUT)
led4 = Pin(12, Pin.OUT)
while True:
led1.value(0)
led2.value(0)
led3.value(0)
led4.value(0)
sleep(.5)
led1.value(0)
led2.value(0)
led3.value(0)
led4.value(1)
sleep(.5)
led1.value(0)
led2.value(0)
led3.value(1)
led4.value(0)
sleep(.5)
led1.value(0)
led2.value(0)
led3.value(1)
led4.value(1)
sleep(.5)
led1.value(0)
led2.value(1)
led3.value(0)
led4.value(0)
sleep(.5)
led1.value(0)
led2.value(1)
led3.value(0)
led4.value(1)
sleep(.5)
led1.value(0)
led2.value(1)
led3.value(1)
led4.value(0)
sleep(.5)
led1.value(0)
led2.value(1)
led3.value(1)
led4.value(1)
sleep(.5)
led1.value(1)
led2.value(0)
led3.value(0)
led4.value(0)
sleep(.5)
led1.value(1)
led2.value(0)
led3.value(0)
led4.value(1)
sleep(.5)
led1.value(1)
led2.value(0)
led3.value(1)
led4.value(0)
sleep(.5)
led1.value(1)
led2.value(0)
led3.value(1)
led4.value(1)
sleep(.5)
led1.value(1)
led2.value(1)
led3.value(0)
led4.value(0)
sleep(.5)
led1.value(1)
led2.value(1)
led3.value(0)
led4.value(1)
sleep(.5)
led1.value(1)
led2.value(1)
led3.value(1)
led4.value(0)
sleep(.5)
led1.value(1)
led2.value(1)
led3.value(1)
led4.value(1)
sleep(.5)
https://www.youtube.com/watch?v=P1dzHNgAtvg&list=PLGs0VKk2DiYz8js1SJog21cDhkBqyAhC5&index=4
Subscribe to:
Posts (Atom)