TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Ras Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • LED Dance Suit
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
  • Random Hacks
    • Movile

This program takes the HTML code from a websites and uses an algorithm to calculate a co-ordinate on the Unicorn HAT.  This LED is then briefly flashed on and off.  What this creates is a colour visualisation of a website.  You could think of it as a digital light signature.  

1. Coding a location for each LED


To get started I originally began creating a dictionary of coordinates that related to each LED on the Unicorn and the corresponding letter in the Alphabet.  For example letter A would be the co-ordinates 0,0 and the letter B would be 0, 1 and so on.  However, this became complicated as I wanted a specific LED to light up for each individual letter.  Thanks to @Gagetiod and his help, he suggested using the ord() function which converts a letter /  character to its corresponding ASCII value.   Dividing the value by 8 then calculates the a value for the x part of the LED co-ordinate and finding the modulus returns the y coordinate.   Now every letter, charater or symbol can be converted to an X and Y location on the Unicorn HAT

2. Using an URL to pull down the HTML code for a Website



Download the Code Here


Letter Grid
File Size: 14 kb
File Type: docx
Download File

Picture
Once LEDs and the letters where assigned I created a simple string input to test the program.  I then got carried away and began to wonder what the HTML code behind a website would look like as a set of colors on an 8 x 8 LED grid of bright light!  Using the urllib2 and the code urllib2.urlopen(name of the website) the HTML could be added to a variable.  Then each of the characters in the variable can be parsed through, the co-ordinates calculated and then the LED light up.
Letter to ASCII Vaue
index  = ord(letter)-65
if index > 0:
       x = int(index/8.0)
       y = int(index%8)
       print (x, y)

3. Sparkles


If the ASCII number is below 0 the value of zero then the LEDs could not be located.  Therefore I used @Ben_Nuttal's random sparkle program to select a random LED and colour - adds more variety. 
  x = randint(0, 7),   y = randint(0, 7),   r = randint(0, 255)
  g = randint(0, 255),   b = randint(0, 255),   UH.set_pixel(x, y, r, g, b)
 UH.show(),  time.sleep(0.10),   UH.clear()
Powered by Create your own unique website with customizable templates.