#!/usr/bin/python # -*- coding: utf-8 -*- # qrmovie import time # need to use git://github.com/mozillazg/python-qrcode.git import qrcode from PIL import Image, ImageFont import ImageOps # uses bgreat's SPI code; see # raspberrypi.org/phpBB3/viewtopic.php?f=32&t=9814&p=262274&hilit=nokia#p261925 import nokiaSPI noki = nokiaSPI.NokiaSPI()Â Â Â Â Â Â Â Â Â Â Â Â Â # create display device qr = qrcode.QRCode(version=1,Â Â Â Â Â Â Â Â Â Â # V.1 QR Code: 21x21 px error_correction=qrcode.constants.ERROR_CORRECT_M, box_size=2, border=1) bg = Image.new('1', (84, 48))Â Â Â Â Â Â Â Â Â Â # blank (black) image background # intro noki.cls() noki.led(0) time.sleep(3) for i in range(0,769,32): noki.led(i) time.sleep(0.04) # display is 14 columns by 8 rows noki.centre_word(1, 'scruss.com') noki.centre_word(3, 'presents') time.sleep(3) noki.cls() noki.centre_word(1, 'qrclock') noki.centre_word(2, 'the') noki.gotorc(3,3) noki.text("[Q]uite") noki.gotorc(4,3) noki.text("[R]ubbish") noki.gotorc(5,3) noki.text(" Clock") time.sleep(3) elapsed=0 start_time = time.time() while (elapsed<12): qr.clear() newbg = bg.copy()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # copy blank background s = time.strftime('%Y-%m-%d %H:%M:%S') qr.add_data(s)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # make QR Code of YYYY-MM-DD HH:MM:SS qr.make() qrim = qr.make_image()Â Â Â Â Â Â Â Â Â Â Â Â Â # convert qrcode object to PIL image qrim = qrim.convert('L')Â Â Â Â Â Â Â Â Â Â Â # make greyscale qrim = ImageOps.invert(qrim)Â Â Â Â Â Â Â # invert colours: B->W and W->B qrim = qrim.convert('1')Â Â Â Â Â Â Â Â Â Â Â # convert back to 1-bit newbg.paste(qrim, (18, 0))Â Â Â Â Â Â Â Â Â # paste QR Code into blank background noki.show_image(newbg)Â Â Â Â Â Â Â Â Â Â Â Â Â # display code on LCD time.sleep(0.4)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # pause before next display elapsed = time.time() - start_time noki.cls() noki.centre_word(1, 'for') noki.centre_word(2, 'more') noki.centre_word(3, 'details') time.sleep(3) noki.cls() noki.load_bitmap("blogpost-nokia.bmp", True) time.sleep(7) noki.cls() noki.centre_word(3, 'fin') noki.centre_word(5, 'scruss, 2013') time.sleep(1) for i in range(768,-1,-32): noki.led(i) time.sleep(0.05) time.sleep(1) noki.cls()
(This source, plus nokiaSPI class: qrclock-movie.zip)
Lines 43-58 show off the QR clock for a maximum of 12 seconds. Any more, and you’d get really bored.
The screen handling functions I used are:
- cls() â€” Clears the screen.
- led(brightness) â€” sets the backlight to brightness. For me, full brightness is at 768. A value of zero turns the backlight off. If you don’t have the screen LED connected to one of the Raspberry Pi’s PWM pin, this will either be full on (for any brightness >= 1), or off, for brightness=0. This is used to fade up the screen in lines 24-26, and fade it down far too theatrically in lines 72-74.
- show_image(PILImage) â€” display a single bit depth black and white Python Imaging Library object PILImage. This can be no larger than 84Ã—48 pixels.
- load_bitmap(file, Invert) â€” load a single bit depth black and white BMP file of maximum size 48Ã—84. If Invert is true, keep the colours as they are, otherwise swap black and white to make a negative image. nokiSPI flips images by 90Â°, so the image I loaded to show the URL of the blog post looks like this:
(I know, I could have generated this in code, but I’d already made the image using qrencode. I couldn’t be bothered working out the image size and offsets.)
The text handling functions I used are:
- gotorc(row, column) â€” move the text cursor to row, column. The screen only has 14 columns by 8 rows if you use the standard 6Ã—6 pixel font, so keep your text short to avoid disappointment.
- text(text) â€” write text at the current cursor position.
- centre_word(row, text) â€” write text centred in row row. Since the text rows are a maximum of 14 columns, text with an odd number of characters will appear slightly off-centre.
There are many more functions in the nokiaSPI class; watch the demo, have a dig through the source and see what you can use.
Copyright Info: The Star Spangled Banner
Your video, The Star Spangled Banner , may include content that is owned or administered by these entities:
- Entity: Music Publishing Rights Collecting Society Content Type: Musical Composition
What should I do?
No action is required on your part. Your video is still available worldwide. In some cases ads may appear next to your video.
What can I do about my video’s status?
Please note that the video’s status can change, if the policies chosen by the content owners change. You may want to check back periodically to see if you have new options available to you.
Under certain circumstances, you may dispute this copyright claim. These are:
- if the content is mistakenly identified and is actually completely your original creation;
- if you believe your use does not infringe copyright (e.g. it is fair use under US law);
- if you are actually licensed by the owner to use this content.
I need more information. I want to learn more about the dispute process.
Please take a few minutes to visit our Help Center section on Policy and Copyright Guidelines, where you can learn more about copyright law and our Content Identification Service.
A little bit of silliness for Thanksgiving:
This took almost no time to put together. The “speaker” is a Tim Hortons cup with a cheap piezo glued to the base. What makes the Arduino sing is the Tone Library running its RTTTL demo sketch, with the anthem itself pasted in from a rather old Nokia Ringtones library.
Update: Here’s the code, such as it is. It’s just the Tone/examples/RTTTL code with the tune data pasted in. I’d been programming Arduino for about a year, so that was a semi-major achievement for me:
It’s nice to revisit old code and find it was written by a friend, Brett Hagman of Rogue Robotics.
Genius: Cape Wind Comedy Daily.
And we thought this was teh k00l v1d in 1981: Landscape – “Einstein a Go-Go”