Adafruit Playground is a wonderful place to share what you find interesting. Have a cool project you are working on? Have a bit of code that you think others will find useful? Want to show off your electronics workbench? You have come to the right place.
Adafruit Playground is a safe place to share with the wonderful Adafruit community of makers and doers.
-
Pinned by mrklingon
Meet MrKlingon - Joel Anderson
Joel, aka MrKlingon, is a lifelong SF enthusiast who has been playing with computers for about as long as he remembers. From a Think-a-Tron, to Digicomp, to science fair projects, he has always loved thinking of interesting computing projects.
Retired from work in network security for a Big Ten university at the beginning of the pandemic, he delighted in discovering all the great things Adafruit had to experiment with. Particularly interesting has been coming up with ways to squeeze all sorts of things out of the tiny Neo Trinkey.
-
Babel - Let's make some Alien words!!
Here's another silly NeoTrinkey project - let's make some alien words!
babel.py - generates "alien" words using a set of rules for Wookie, Klingon, Vulcan, Mando'a and Romulan.
ncount.py - blinks numbers
Touching pad #1 toggles between the five languages, and blinks the number (1..5) for the language choice. Each language defines a set of consonants, vowels and an array of word patterns (V for vowel, C for consonant, v 50% chance for a vowel, c 50% chance for consonant). When you touch pad #2, a list of words (random quantity, 1 to 10) is created following the rule sets. The rule sets were created using known words from those languages.
Change the variable REPL to direct the output: True means the program prints to the repl, False sends the output to the keyboard.
Example output:
Wookie: OUWA ROR HOH AROOAUW HOUW WOH ORAUW ORUUUUR WOR OWOUOOR
Klingon: laq noegh tSyIm DIyS mI Ho jaab
Vulcan: su tuai tiustoa het' tiy k' t
Mando'a: ary reara 'hr syc tmn cor khc
Romulan: ihf ki'vh ies lu'm m'ih ih eenh hieh uek
Note: These are generated words, and only by coincidence match vocabulary in any real lexicons.
For fun you can replace my rule sets for any other alien or fantasy language you wish to create.
-
Tell me a story, Neo Trinkey!
Once upon a time.....
..... I remember reading a story in "Summer Weekly Reader" (I think by Isaac Asimov) about a robot that told stories to the young boy who owned it. Mostly fairy tales, till one of the boy's friends loaded a tape with more modern info like spaceships (and robots!).
Now, I don't have that robot... but I have a Neo Trinkey and CircuitPython - that's more than enough.
My repository TellMeAStory has two files, scifi.py and prt.py. Copy those to a Neo Trinkey, renaming scifi.py to code.py. When the program runs, touching "1" chooses a planet name, and touching "2" will generate a short story. In code.py, if REPL=True, you'll need to be in an editor like mu to see the text. IF you change REPL to be False, then it will use HID support to send the text as if typed on a keyboard! For example:
(touching 1)
Broria KBO6
(touching 2)
Black Sparrow
lifts off from
Broria KBO6
with ancient artifacts
and is damaged in an explosion
and tumbles out of control till emergency crews reach them
Suddenly a ship appears from Notania warning of imminent Bhisih attack.
Planets, Aliens, and Ship names were generated on fantasynamegenerators.com - you can edit the lists with your own choices. And you can rewrite the story elements to your own liking!
-
Spock on a Chip!
I love using the random library - it's a simple way to introduce variety into simple programs and here's one example, what I call "Spock on a Chip." Here's a link to the repository.
Copy the files to a NeoTrinkey, changing "spock.py" to "code.py" - when it runs, it occasionally blinks lights, but when you touch one of the pads, it will blink and then pick a random quote out of the "spock" file and print it. If REPL=True, you'll need to be in an editor like mu to see the text. IF you change REPL to be False, then it will use HID support to send the text as if typed on a keyboard! Just the way to jazz up your email! Edit the "spock" file to add your own favorite quotes from everyone's favorite Vulcan.
What's going on?
There are two functions that are used to deliver the quotes. len_file(filename),
def file_len(filename):
with open(filename) as f:
for i, _ in enumerate(f):
pass
return i + 1
and wisdom(file_name).
def wisdom(filename):
qs = open(filename)
for i in range(random.randrange(file_len(filename))+1):
quote = qs.readline()
quote = quote.rstrip()
cmpthink()
qs.close()
return (quote.rstrip())
Give a file name, wisdom() calls len_file() to determine how big the file is, then uses random.randrange() to select the text - that means you can add or subtract from the "spock" file without needing to update the program.
The fun thing with this code is, it can be reused for other purposes. I've already used it to put together a "story" program that uses multiple source files (aliens, suns, planets, etc.) that can be drawn from to generate story lines. It could be used for a diceware style passphrase generator. And, of course, it doesn't have to be Spock on a chip - you can fill the "spock" file with any quotes you choose.
-
How about.... a 4 Pixel Video Game??
Here's a project I had fun putting together using my NeoTrinkey toolkit to make a tiny little video game.
I call it "Galaga" - and it uses the ncount.py and morse.py helper modules.
Gameplay:
- An enemy moves back and forth at random in the 0 and 3 neopixels.
- Touch 1, or 2 to "shoot" the moving enemy (green pixel).
- If you are lined up with it, you get a hit. If not it's a miss.
- A hit blinks gold for the count of hits. If you miss, you blink the number of misses in pale blue.
- A win is 5 hits, and losing is when you have 5 misses or run out of missiles.
- Winning is followed by multicolored blinking.
- Following loss/win the number of missiles, score and miss count are reset and game restarts.
- NOTE: connected to Thonny or Mu, you can see "boom!" and "miss" printed when you hit or miss. Plus notification when you win (or lose).
-
NeoTrinkey Tool Kit!
It's no secret I think the NeoTrinkey is wonderful. It's small, it's cheap and it runs CircuitPython! Who could ask for more??
As I played with it, one thing I found handy was making some helper modules to assist in building programs - three that are particularly handy are:
-
morse.py - translate text to Morse code, also defines touch pads for input
- def docode(text): # display given text in Morse code
- def blinknum(num,color): #count out a number in a color
- def compthink(): #blink out all the colors when computer "thinking"
-
prt.py - provides a function to print text to the REPL *OR* using HID to send it as typed text.
- def prt(text, REPL): #prints text to REPL if REPL=True; otherwise uses HID to send as typed text
-
ncount.py - blinks numbers, or displays 0-15 in binary.
- def docolor(color): #briefly set all pixels to color
- def blinknum(num,color): #blinks num times in color
- def binnum(num,color): #display num%16 in binary on pixels with color
Using The Modules
Here's a very short program that blinks out, in Morse code some Bible verse fragments (in Klingon - my "nickname" is mrklingon, after all):
from morse import *
John316 = "vaD joH'a' vaj loved the qo'"
Isaiah263 = "Duvoqchugh, vaj rojna'Daq Da'av, DuHarmo'"
Psalm231 = "DevwI'wI' ghaH joH'a''e' jIneHbe'."
while True:
docode(John316)
docode(Isaiah263)
docode(Psalm231)
Pretty simple - it just blinks the code over and over. You could plug it into a power source and let it run - and you could choose your own text. Plugged into a computer running Mu, you would see the text being printed over and over as well.
Using the prt.py module, I wrote magicquest.py. This uses morse.py for the touch pad initialization, and the "compthink()" blinking. Touching pad 1 creates a fantasy character (race, class and name), and pad 2 generates a short story about the character's adventure. I used fantasynamegenerators.com to come up with place names and more.
If you change the value of REPL in the code you can decide if the text gets printed in the REPL using Mu or Thonny, or if it is sent as if typed using a computer.
REPL = False #"printed" text from prt() goes as if typed
REPL = True #"printed" text goes to REPL
I used the ncount.py module's binnum() function in two progams, cards.py and orbit.py.
For the cards.py program, the neotrinkey shuffles a deck of cards when you touch pad1, and pad2 draws a card and prints it in the REPL but displays it as a binary number (1-13) and color
suits = ["diamonds","clubs","hearts","spades"]
scolor = [gold,blue,red,green]Touching 1 and 2 together shuffles and draws three cards.
orbit.py blinks a purple NeoPixel around and around at a speed (sort-of) appropriate to the planet the ship is at - from Mercury to Pluto. This uses binnum() to light up the number 1,2,4, or 8 to move the position around and around the four NeoPixels. Touching pad 1 makes all NeoPixels flash gold (closer to the sun) and shifts to the planet that is next closer to the sun. Touching pad 2 makes all NeoPixels flash blue (farther from the sun) and shifts to the planet next farther out.
Pads 1&2 together make jump the position either to Mercury or Pluto depending on whether you are closer than Mars or at Mar or farther out.
The name of the target planet is printed to the REPL and the orbit speed speeds up or slows down depending on which direction you have moved. (Note: the "speed" is just a factor based the position (planet 1-9) divided by ten. It is not really correct for the real planets).
-
morse.py - translate text to Morse code, also defines touch pads for input
-
Cosmos in a NeoTrinkey!
Yet another silly program from MrKlingon.
Program cosmos.py requires ncount.py to display numbers. You can load both on a neotrinkey. If cosmos.py is saved as code.py the program runs on power up.
A 40x40 cosmos is generated with a variety of stars.
- Touching pad1 changes direction - there are 8 - (think N, NE, E, SE, S, SW, W, NW). The neotrinkey display shows a binary number for which ever is the current direction, then the current X,Y position, then displays the stars at the current 2x2 window the "ship" is at.
- Touching pad2 blinks through showing the stars for 7 steps in the current direction.
- Touching both pads together (1&2) does a display traversing through all the stars.
- Running in Thonny IDE displays current coordinates while "traversing" and names the stars.
-
Ridiculous "Light Saber"
Who doesn't want a light saber? There are lots of projects using neopixels (and products as well). Here's a silly "saber" (dagger? scalpel?) using a neotrinkey. It won't impress many, but it was fun to put together. When you put this in as "code.py" on a neotrinkey, you can plug it into any power source and it will first blink "hello" in Morse Code, then touching pad one will choose a random color. Touching pad two will "ignite" or "douse" the saber.
I originally wrote a saber for a Gemma M0 with a 30 neopixel strip. I didn't like blinking all the saber's lights on/off, and rewrote it to ignite/douse more slowly to make it realistic (as realistic as an imaginary weapon is, of course). Then... I thought it would be just as fun (and more portable) to do the same thing on one of my beloved neotrinkeys. So here it is:
-
Why not a $6 Web Server
So... the Pico Pi W can connect to Wifi. What to do with that? Hmmm...
-
Teach your NeoTrinkey Morse code!
C3P0 can talk. R2D2 expresses what he's thinking with beeps and boops. What can you do with a Neo Trinkey?
How about.....Morse code? It's simple, and four neopixels is more than enough to say anything! Here's how I set about doing it.