[{"element_type":"image_url","content":"https://cdn-learn.adafruit.com/guides/cropped_images/000/003/300/medium640/NeoT_top_angle_cropped.jpg?1617719423","metadata":{"alt":"The","caption":"What can you do with a computer this small? "}},{"element_type":"text","content":"\n  \n\u003cp\u003eC3P0 can talk. R2D2 expresses what he's thinking with beeps and boops.\u0026nbsp;\u003cem\u003eWhat\u003c/em\u003e can you do with a Neo Trinkey?\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eHow about.....\u003cem\u003e\u003ca href=\"https://en.wikipedia.org/wiki/Morse_code\" target=\"_blank\"\u003eMorse code?\u003c/a\u003e\u003c/em\u003e It's simple, and four neopixels is more than enough to say anything! Here's how I set about doing it.\u003c/p\u003e\n\n","metadata":{}},{"element_type":"text","content":"\n  \n\u003cp\u003eThe great thing about Circuit Python is you can just plug in a device and use any editor on the code, but I like to use \u003ca href=\"https://thonny.org\" target=\"_blank\"\u003e\u003cem\u003e\u003cstrong\u003ethonny\u003c/strong\u003e\u003c/em\u003e\u003c/a\u003e as my IDE. Thonny gives you easy access to the REPL and you can have plenty of print() statements for debugging.\u003c/p\u003e\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/022/original/thonny.png?1666193863","metadata":{"caption":""}},{"element_type":"text","content":"\n  \n        \u003cp\u003eUsing Thonny, I created a support module, \u003ca href=\"https://github.com/mrklingon/neotrinkey/blob/main/morse.py\" target=\"_blank\"\u003emorse.py \u003c/a\u003ethat provides a framework for displaying morse code text:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eencryption(text) - returns text in morse code\u003c/li\u003e\n\u003cli\u003edot() - displays \"dot\" in green\u003c/li\u003e\n\u003cli\u003edash() - displays \"dash\" in blue\u003c/li\u003e\n\u003cli\u003espace() - separates code letters in purple\u003c/li\u003e\n\u003cli\u003eblinkcode(code) - blinks out morse text\u003c/li\u003e\n\u003cli\u003edocode(text) - encrypts in morse, then blinks text\u003c/li\u003e\n\u003cli\u003eIn addition, I defined a set of colors \u003cspan\u003e[\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003epink\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003egold\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003eblue\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003eorange\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003egreen\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003ered\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003epaleblue\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003ewhite\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e,\u003c/span\u003e\u003cspan class=\"pl-s1\"\u003e\u003cspan class=\"pl-token\"\u003epurple\u003c/span\u003e\u003c/span\u003e\u003cspan\u003e] and some fun routines:\u003c/span\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003eblinknum(number, color) - blinks color number time\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003edocolor (color) - briefly sets all pixels to color\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003ecompthink(number) - cycles through all colors number times (it's supposed to represent the computer \"thinking\")\u003c/span\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003cp\u003e\u003cspan\u003eFinally, morse.py sets up the touch pads for use as input.\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003eIt's *NOT* a program -\u0026nbsp; \u0026nbsp;if you run this code in Thonny, it just completes and returns to the REPL prompt.\u0026nbsp;\u003cem\u003eBut\u003c/em\u003e then you can test the functions:\u003c/p\u003e\n      \n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/000/023/original/thonny-working.jpg?1666195058","metadata":{"caption":""}},{"element_type":"text","content":"\n        \u003cp\u003eHere you can see\u0026nbsp;\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eThonny loaded with morse.py,\u003c/li\u003e\n\u003cli\u003eExecuted the code, and returned to the prompt,\u003c/li\u003e\n\u003cli\u003eentered\u0026nbsp; \"docode(\"hello\")\"\u0026nbsp;\u003c/li\u003e\n\u003cli\u003eoutput of encryption (I included diagnostic print of the encryption for use in Thonny). What you don't see is the NeoTrinkey blinking out the text.\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eNow... how to make that into a\u0026nbsp;\u003cem\u003eprogram\u003c/em\u003e? So I wrote \u003ca href=\"https://github.com/mrklingon/neotrinkey/blob/main/DoMorse.py\" target=\"_blank\"\u003eDoMorse.py\u003c/a\u003e to take advantage of morse.py and give you a \"menu\" of four message.\u003c/p\u003e\n      ","metadata":{}},{"element_type":"code","content":"from morse import *\n\nmessage1 = \"abcdefghijklmnopqrstuvwxyz\"\nmessage2 = \"Live long and prosper!\"\nmessage3 = \"May the force be with you!\"\nmessage4 = \"Never give up, never surrender!\"\n\ntexts = [message1,message2,message3,message4]\n\nDone  = False\n\ncount = 0\n\ncompthink() #computer thinking\ndocode(\"hello\") #say hello\nblinknum(1,blue)\n\nwhile not Done:\n    val = 0\n\n    if touch1.value: \n        val = val + 1\n\n    if touch2.value:\n        val = val + 2\n\n\n    if val == 1: #advance through messages touching \"1\"\n        count = count+1\n        if count == 4:\n            count = 0\n        blinknum (count+1,blue) #display index+1\n\n    if val == 2: #display message in Morse when touching \"2\"\n        docode(texts[count])\n        compthink() #indicates end of message\n\n    time.sleep(.2)","metadata":{"language":"python","linenums":false}},{"element_type":"text","content":"\n  \n\u003cp\u003eAnd there you have it - your Neo Trinkey can \"talk!\" With this routine renamed as \"code.py\", your Neo Trinkey can be plugged into a computer, a battery - any USB power source, and it is ready to blink out one of four messages.\u003c/p\u003e\n\u003cp\u003eTouch \"1\" to step through 1,2,3,4 (it will blink blue lights 1,2,3 or 4 times to tell you which message it is on).\u003c/p\u003e\n\u003cp\u003eTouch \"2' to display the message in Morse code.\u003c/p\u003e\n\u003cp\u003eI chose the alphabet as the first message since it's a nice way to familiarize yourself with the full Morse alphabet. You can change the other messages to your choice - even add more than four, if you update the code to cycle through more than four messages.\u003c/p\u003e\n\n","metadata":{}}]