[Tutor] Magic numbers

Dennis Lee Bieber wlfraed at ix.netcom.com
Fri Aug 6 15:04:43 EDT 2021


On Fri, 6 Aug 2021 11:08:35 +1000, Phil <phillor9 at gmail.com> declaimed the
following:


>I'm simulating a shift register that can shift either left or right. I 
>start with bit 0 equal to one and shift it to the right until I hit the

	Most people would be shifting a 1 LEFT to reach that 128, than shift
right to get back to the first bit.
 
>most significant bit , for example 128 for an 8 bit shift register, and 
>then reverse the shift until I return to bit zero. Looping forever to 
>create a Cylon effect (everyone remembers Lorne Green in Battlestar 

	The common name for that is a "Larson Scanner"; he used the same
technique on KITT (Knight Rider).

https://learn.adafruit.com/larson-scanner-shades

>Galactica, don't they?). An and mask is applied to determine the status 
>of each bit which in turn controls the state of my array of on-screen LEDs.
>

	Well, no LEDs emulated here, just 0/1, but the core of a Larson Scanner


import time

LED = 1
print(format(LED, "08b"), end="\r", flush=True)
while True:
    for i in range(8):
        print(format(LED, "08b"), end="\r", flush=True)
        LED = LED << 1
        time.sleep(0.125)
    for i in range(8):
        LED = LED >> 1
        print(format(LED, "08b"), end="\r", flush=True)
        time.sleep(0.125)


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/



More information about the Tutor mailing list