Mystery Box: NeoMatrix Mk I

Similar documents
Interior Purse Light. Created by Becky Stern. Last updated on :41:08 PM UTC

NeoMatrix 8x8 Word Clock

Portable Apple Watch Charger

3D Printed 20w Amplifier Box

Neon LED Signs. Created by John Park. Last updated on :11:09 PM UTC

Trinket-Powered Conference Room Occupancy Display

Clockwork Goggles. Created by John Park. Last updated on :03:10 PM UTC

Chirping Plush Owl Toy

Interactive Gift Box. Created by codingpro. Last updated on :47:40 AM UTC

NeoPixel Ring Bangle Bracelet

Con Badge with Circuit Playground Express

Solar Boost Bag. Created by Becky Stern. Last updated on :44:55 PM UTC

Light-Up Angler Fish Embroidery

Coffee Detonator: The TNT Plunger Grinder

Adafruit Capacitive Touch Sensor Breakouts

Mad Science Test Tube Rack

3D Printed 20w Amplifier Box

Feather Weather Lamp. Created by Ruiz Brothers. Last updated on :54:26 PM UTC

i2c/spi LCD Backpack Created by lady ada Last updated on :11:04 PM UTC

NeoPixel Bike Light. Created by Ruiz Brothers. Last updated on :43:46 PM UTC

FLORA TV-B-Gone. Created by Becky Stern. Last updated on :32:57 PM UTC

Trinket NeoPixel LED Longboard

Trellis 3D Printed Enclosure

Bunny Ears with MakeCode

Guardian Shield+ Zelda Breath of the Wild

Adafruit VL53L0X Time of Flight Micro-LIDAR Distance Sensor Breakout

Lie Ren's Stormflower Gun Blade

Adabot Operation Game

3D Printed Camera LED Ring

FPV Mini Display. Created by Ruiz Brothers. Last updated on :00:18 PM UTC

ISS Pin. Created by Leslie Birch. Last updated on :27:30 PM UTC

Toy Car Speed Timer. Created by Kirby Griese. Last updated on :13:49 PM UTC

7 Portable Multitouch Raspberry Pi Tablet

Sword & Wand Prop Effects with Circuit Playground

NeoPixie Dust Bag with Circuit Playground Express

Jewel Hair Stick. Created by Leslie Birch. Last updated on :47:17 PM UTC

Fiddy - the FTDI Clip

3D Printed Case for Adafruit Feather

Adafruit TPL5110 Power Timer Breakout

7" Portable HDMI Monitor

Circuit Playground Yoyo

Magical Mistletoe. Created by Leslie Birch. Last updated on :45:29 PM UTC

FLORA Pixel Brooch. Created by Becky Stern. Last updated on :19:07 PM EST

Pushrod Garage. Created by John Park. Last updated on :07:30 PM UTC

Android GBoard Morse Code Control with Circuit Playground Express

Bike Wheel POV Display

Tent Lantern. Created by Timothy Reese. Last updated on :17:25 AM UTC

Fiddy - the FTDI Clip

Flora Brake Light Backpack

Cup o' Sound. Created by Becky Stern. Last updated on :30:06 PM EST

Crickit Dancing Marionette Kit Created by Dano Wall. Last updated on :03:11 PM UTC

Getting Started with FLORA

3D Printed Google AIY Voice Kit

Introducing Adafruit Trellis

Arduino Lesson 6. Digital Inputs

Ping Pong Ball Launcher

Adafruit LED Sequins. Created by Becky Stern. Last updated on :02:00 AM UTC

Naughty or Nice Machine

Adafruit APDS9960 breakout

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :42:16 PM UTC

Monochrome OLED Breakouts

3D Printed LED Knuckle Jewelry

Adafruit Color Sensors

Adafruit PowerBoost 500 Shield

Infinity Mirror Valentine's Candy Box

Adafruit Mini TFT " 160x80

Raspberry Pi Selfie Bot

MCP Bit DAC Tutorial

PyPortal View Master Created by Ruiz Brothers. Last updated on :51:28 AM UTC

Adafruit 1.27" and 1.5" Color OLED Breakout Board

Adafruit 8x16 LED Matrix FeatherWing

Adafruit TPL5111 Reset Enable Timer Breakout

Bluetooth Controlled NeoPixel Headphones

Alohamora Bottle. Created by Erin St Blaine. Last updated on :58:53 PM UTC

NeoPixel Manicure. Created by Sophy Wong. Last updated on :50:38 PM UTC

GPS Logging Dog Harness

'Sup Brows. Created by Kate Hartman. Last updated on :52:04 PM UTC

Adafruit GPIO Expander Bonnet for Raspberry Pi Created by Kattni Rembor. Last updated on :12:47 PM UTC

Circuit Playground Kaleidoscope

Slider Crank Mechanism -- from Cardboard and Craft Sticks

Adafruit AMG8833 8x8 Thermal Camera Sensor

Adafruit DRV2605 Haptic Controller Breakout

Mystery Box: Haunted Radio

MiniPOV4 - DIY Full-Color Persistence of Vision & Light-Painting Kit

Hammer Time Mini Golf Hazard with Crickit

Getting Started with FLORA

MCP Bit DAC Tutorial

Adafruit Si7021 Temperature + Humidity Sensor

Joy Featherwing. Created by Dean Miller. Last updated on :03:07 PM UTC

Audio Prank Gift Box. Created by Becky Stern. Last updated on :46:15 PM UTC

LED Eyes. Created by Ruiz Brothers. Last updated on :50:55 AM UTC

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Overwatch Prop Gun: Lucio's Blaster Pt. 3

Adafruit Si5351 Clock Generator Breakout

FLORA and GEMMA ICSP. Created by Becky Stern. Last updated on :30:55 PM EST

Circuit Playground Express Laser Tag

Paper Airplane Launcher

Crawling Animatronic Hand

Mystical LED Halloween Hood

TSL2561 Luminosity Sensor

Transcription:

Mystery Box: NeoMatrix Mk I Created by John Park Last updated on 2017-12-01 07:31:05 PM UTC

Guide Contents Guide Contents Overview Make the Panels Build the NeoMatrix Keypad Display Modules Metro Mounting Potentiometer Mounting Piezo Buzzer Side Panels Pushbutton USB Jack Wiring Everything Together Low Profile Interconnects NeoSegment Wiring Piezo Connection Potentiometer Wiring Pushbutton Wiring USB Port Closing the Case Code and Use Board Manager Keypad NeoSegment Coding 2 3 6 9 9 11 14 16 18 20 21 22 22 22 25 27 28 31 32 34 39 39 41 42 42 Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 2 of 49

Overview Imagine all of the things you can do with a NeoMatrix Mk I, the Interface of Infinite Possibilities! From puzzle box to step sequencer, from NeoPixel programmer to crypto generator, from TV prop to phone phreaking device, the choices are endless. Think of it as a platform for experimentation and interface design. At the core of the NeoMatrix Mk I is a NeoSegment RGB LED character display, driven by an Adafruit Metro with a phone pad 3x4 button matrix and two knobs as inputs. It also has a built in piezo buzzer for sound indicators. The NeoMatrix Mk I has a lighted pushbutton that can be used for any purpose you like, and an externally accessible USB port for data and power. You could also convert it to run from battery power with a USB battery pack or a LiPo battery and PowerBoost. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 3 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 4 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 5 of 49

Make the Panels You can house your NeoMatrix Mk I circuit, display, and inputs in any sort of enclosure you like -- 3D printed, cut from cardboard, fashioned from wood, it's up to you. If you'd like to cut one on a laser cutter, you can use the plans here. They are designed to be cut from 1/8" material -- either baltic birch plywood or acrylic will work very nicely. Download the two.svg files below and prepare them for ethcing and cutting on the laser cutter software of your choice. I used an Epilog Zing 40 Watt laser cutter with the print driver from within Rhino. The neomatrixbox_raster.svg file is for engraving the graphics. It's helpful to engrave the material first, so that if any parts shift after cutting the graphics are already registered properly. I used these etching settings: Speed: 70% Power: 70% DPI: 500 neomatrixbox_raster.svg https://adafru.it/abi Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 6 of 49

Everything fits on a 12" x 12" piece of material. Here you can see that I'm using a bit of tape at the edges to fight the slight warping of the wood, which can throw off the laser focus. Etching graphics is an optional step. You'll notice in some of the photographs the first iteration of the NeoMatrix Mk I was made without graphics. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 7 of 49

The neomatrixbox.svg is the cutting file. I used the following settings: Speed: 60% Power: 55% Frequency: 500 neomatrixbox.svg https://adafru.it/abj If you don't have access locally to a laser cutter, such as a maker space, you can also send the files off to a laser cutting service. Ponoko is a good choice. Once you've got your parts cut, it's time to assemble the NeoMatrix MkI! Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 8 of 49

Build the NeoMatrix The NeoMatrix Mk I circuit is diagrammed above. You can refer to this while connecting the components during assembly. Keypad Begin assembly by affixing components to the inside of the front panel, starting with the keypad. The keypad fits in place from the inside and you can then secure it with four of the 9.5mm long M2.5 nylon screws and nuts. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 9 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 10 of 49

Display Modules The NeoSegment modules will also be assembled from the inside of the front panel, however, they require a bit of preparation first. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 11 of 49

Connect the three NeoSegment modules with their built-in connectors. Then, take the large piece of material that was cut from the panel window and affix it to the back of the NeoSegments with a length of double-stick foam tape. Use the two small pieces of wood that were cut from the window as sides to box in the panel. (Note: in the final laser cutting file these scrap pieces will be cut for you from the window panel.) Affix these to the display as shown with foam tape, and use a bit of wood glue to attach to the inside of the panel. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 12 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 13 of 49

Metro Mounting We'll use nylon hex standoffs to mount the Adafruit Metro board to the inside of the front panel. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 14 of 49

Place four medium nylon M2.5 screws into the front panel from the outside/front facing in Screw the four stand offs to the screws from the inside of the front panel Use the four short M2.5 screws to screw the Metro in place on the hex stand offs Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 15 of 49

Potentiometer Mounting The two potentiometers will be mounted from the inside of the front panel and screwed into place with their included hex nuts. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 16 of 49

Remove the small metal keying tab from each potentiometer with a pair of pliers, so that they can be mounted flush to the panel without adding a keying registration hole. One reason this works is that the soft wood allows the part to still bite in from the compression of the nut alone. If you use acrylic, you may want to also cut a keying tab registration hole to prevent the potentiometers from spinning, since acrylic does not compress Mount the potentiometers from the back side of the front panel as shown Screw the washers and nuts into place from the top Turn the potentiometer shafts to the far left and then place the knobs on them with the indicator at the lower left position. Check that this positioning is symmetrical when the knob is turned to the far right Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 17 of 49

Piezo Buzzer You'll attach the piezo buzzer to the back panel next. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 18 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 19 of 49

Put the piezo into the pre-cut hole from the inside of the back panel Insert the two long M2.5 nylon screws from the outside, then screw on the nuts from the inside Side Panels Next, you'll connect the pushbutton and the USB jack to the two side panels. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 20 of 49

Pushbutton Unscrew the retention collar, then fit the button into it's hole in the left side panel, then screw the collar back on. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 21 of 49

USB Jack Align the USB panel mount jack with the holes from the inside of the right side panel. Then, screw in the two provided screws. Wiring Everything Together Now that everything is assembled, we need to wire all of the parts together. We'll start with the keypad. The keypad matrix uses eight wires to send data to the Metro, which we'll set up in software for pins 2-9. We'll create a custom cable to make this set of connections. Low Profile Interconnects Connecting the electronics is fairly straightforward, however, in order to keep a low profile in a small enclosure, we will Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 22 of 49

need to make 90 degree angle connector cables. A nice, more permanent alternative is to solder the wires directly to the Metro. If you choose this path, start of with the Metro that comes with no headers. Split off an eight conductor section of the jumper wires with the shown colors Use diagonal cutters to cut off a six- and twoconductor set of 90 degree angle jumper pins. Fit the wires' onto the jumper pins as shown Optionally, hit each connection with a small spot of solder to prevent them from wiggling loose later Slide on small sections of heat-shrink tubing, and then heat them up Voila, instant custom interconnect! Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 23 of 49

The other end of the wires can be pressed directly onto the phone keypad pins as shown, with a piece of heat shrink tubing over each one to prevent any shorts. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 24 of 49

Connect the cable to the Metro as shown. NeoSegment Wiring Just like any NeoPixel-based project, we'll need to connect power, ground, and data lines from the Metro to the Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 25 of 49

display. Snip off two two-pin section of 90 degree jumper pins Strip off a brown jumper wire from the pack and fit and solder one end to the "left side" of the short lead of a 90 degree jumper pin as shown Cover the connection with heat shrink tubing Strip off a red and black wire from the pack and fit and solder one end of each to the other two-pin 90 degree jumper, with red on the "left" and black on the "right" as shown in the second image here Insulate the connections with heat shrink tubing Connect the brown jumper pair to pins 12 and 13 on the Metro. Pin 12 will be the data line for the Metro, while we'll use pin 13 later for the pushbutton's internal LED Connect the red/black jumper pair to 5V and GND on the Metro Slide and heat some heat shrink tubing over the the other ends of these three wires. Then connect them to the NeoSegment's interconnect as shown here. Be sure to follow the image closely for wiring order. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 26 of 49

Piezo Connection Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 27 of 49

Connect the piezo's red and black wires to two lengths of jumper wires by sliding the piezo wire ends into the connectors and soldering them Cover the connections with heat shrink tubing Slide another piece of heat shrink tubing over each wire, then connect, solder and insulate each wire to a 90 degree header pin as we have before Plug the black wire into GND on the Metro, and plug the red wire into A1 Potentiometer Wiring Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 28 of 49

Follow the wiring diagram above and the images here for color coding and connection of the wires for the two potentiometers. In order to efficiently utilize the available pins on the Metro, we'll share the one pin each for the voltage and ground on the two pots. You can follow these images for one way to do so. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 29 of 49

Now, plug the ground wires into GND on the Metro, the power wires into 3.3V, and then the two center wiper wires into their respective pins, A2 and A3. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 30 of 49

Pushbutton Wiring The pushbutton has four contacts -- two for the switch and two for the LED. Connect the switch contacts to GND and pin 11, and the LED contacts to GND and pin 13, as shown in the wiring diagram. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 31 of 49

The pushbutton has four contacts -- two for the switch and two for the LED. Connect the switch contacts to GND and pin 11, and the LED contacts to GND and pin 13, as shown in the wiring diagram and images here. Note: the two ground contacts on the switch have been jumpered with some wire and solder so they will share one connection on the Metro. USB Port The final connection to wire is the USB port, which is the easiest! Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 32 of 49

Simply plug it into the USB jack on the Metro, being careful to round the wire neatly so we can close it all up next. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 33 of 49

Closing the Case You can add glue to the side and bottom connections to the faceplate if you like, but just the tight fit and compression force of the four screws is enough to hold the case together nicely. Push the four #6 screws through the front panel, then secure each with a nut Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 34 of 49

Fit the sides, top, and bottom to the front panel, being careful to keep the wiring neatly tucked inside. You can then press the back panel into place over the four screws -- you may need to remove one side or top panel to do this -- then screw on the nuts to secure Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 35 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 36 of 49

Time to add the software! Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 37 of 49

Code and Use Plug in your NeoMatrix Mk I to your computer over USB. Before going any further, make sure you have a basic understanding of how to program and use an Arduino. Thankfully, we have a lot of great tutorials on how this whole thing works. Click here to get started with Arduino, and then come back to this guide to continue. Board Manager To use the Metro board in Arduino, check the Arduino IDE Tools > Board list and select Adafruit Metro. Note: if you don't see the Metro on that list, add this URL to your Arduino > Preferences > Additional Boards Manager URLs: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json Then, go to the Arduino > Tools > Board > Boards Manager... and type 'metro' in the search, then install the Adafruit AVR Boards package. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 38 of 49

Now, pick the Adafruit Metro board from the Arduino > Tools > Board list. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 39 of 49

Keypad To use the 3x4 matrix keypad, you'll need to get a library that adds this functionality to your Metro. Click Arduino > Sketch > Include library... > Manage Libraries, then type 'arduino keypad' in the search box. Install the library shown here. Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 40 of 49

NeoSegment Finally, you'll need to install the NeoSegment library. This makes it easy to program the displays without needing to make calls to the individual NeoPixels behind the segments. This higher level library abstracts things into digits and segments, so you can tell, say, the first digit to display a '4' and the second digit to display an 'A'. Check out the documentation on NeoSegments here. Then, install the library as explained and provided here. Once you've gotten the basic demo examples working, return here. Coding Now, you're ready to code the NeoMatrix Mk I. Copy the code below, then past it into a new Arduino document. Save the file to your Arduino project directory as neomatrixmki.ino, then upload it to the board. #include "Arduino.h" #include "Keypad.h" #include "Neosegment.h" #include <stdlib.h> #define SERIAL_BAUD 115200 #define ndigits 6 // number of digits in display #define NEOSEGPIN 12 #define LEDbrightness 255 // 0 to 255 /* Segment mapping 5 4 6 3 0 2 1 */ int buttonpin = 11; //pushbutton int ledpin = 13; // select the pin for the LED int knobupperpin = A3; // input pin for a potentiometer int knoblowerpin = A2; // input pin for a potentiometer int knobupper = 0; // variable to store the value coming from the sensor int knoblower = 0; // variable to store the value coming from the sensor int buttonstate; int lastbuttonstate = LOW; long lastdebouncetime = 0; long debouncedelay = 50; //initialize the neosegment object Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 41 of 49

//initialize the neosegment object Neosegment neosegment(ndigits, NEOSEGPIN, LEDbrightness); uint16_t i, j; //set up the keypad const byte ROWS = 4; //four rows const byte COLS = 3; //three columns char keys[rows][cols] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'} }; byte rowpins[rows] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad byte colpins[cols] = {2, 3, 4}; //connect to the column pinouts of the keypad //initialize the keypad object Keypad keypad = Keypad( makekeymap(keys), rowpins, colpins, ROWS, COLS ); //use to set digit cursor position int neocounter = 0; //gamma correction table const uint8_t PROGMEM gamma8[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, 69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, 115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, 144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, 177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, 215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 }; void setup(){ Serial.begin(SERIAL_BAUD); pinmode(ledpin, OUTPUT); pinmode(buttonpin, INPUT_PULLUP); digitalwrite(ledpin, HIGH); //turn on the LED neosegment.begin(); neosegment.clearall(); for(int i = 0; i < 6; i++){ //turn on green lines, top row, L to R neosegment.setsegment(i, 5, 0, 40, 0); //the '3' segment is middle dash tone(a1, 330, 100); delay(50); } neosegment.setsegment(5, 6, 0, 40, 0); tone(a1, 330, 100); delay(50); neosegment.setsegment(5, 2, 0, 40, 0); tone(a1, 330, 100); delay(50); Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 42 of 49

neosegment.clearall(); for(int i = 5; i > -1; i--){ //turn on green lines, bottom row, R to L neosegment.setsegment(i, 1, 0, 40, 0); //the '3' segment is middle dash tone(a1, 330, 100); delay(50); } neosegment.setsegment(0, 0, 0, 40, 0); tone(a1, 330, 100); delay(50); neosegment.clearall(); } for(int i = 0; i < 6; i++){ //turn on green lines, middle row, L to R neosegment.setsegment(i, 3, 0, 40, 0); //the '3' segment is middle dash tone(a1, 440, 100); delay(100); } void loop(){ //read button int buttonreading = digitalread(buttonpin); if (buttonreading!= lastbuttonstate) { lastdebouncetime = millis(); } if ((millis() - lastdebouncetime) > debouncedelay){ buttonstate = buttonreading; } Serial.println(buttonState); if(buttonstate){ digitalwrite(ledpin, LOW); } else{ digitalwrite(ledpin, HIGH); } lastbuttonstate = buttonreading; //read knobs knobupper = analogread(knobupperpin); //used for hue knoblower = analogread(knoblowerpin); //used for value //map knob range int knobuppermapped = map(knobupper, 0, 700, 360, 0); int knoblowermapped = map(knoblower, 0, 700, 700, 0); //constrain knob range knobuppermapped = constrain(knobuppermapped, 0, 360); knoblowermapped = constrain(knoblowermapped, 0, 700); //map to hue range //int knobhue = map(knobuppermapped, 0, 255, 0, 360); //knobhue = constrain(knobhue, 0, 360); float knobhue = ((float)knobuppermapped); //map to value range float knobvalue = ((float)knoblowermapped / 700); float r, g, b; float h = knobhue; float s = 1.0; float v = knobvalue; HSVtoRGB(&r, &g, &b, h, s, v); //convert HSV to RGB uint8_t r_byte = (int)(r * 255); Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 43 of 49

uint8_t r_byte = (int)(r * 255); uint8_t g_byte = (int)(g * 255); uint8_t b_byte = (int)(b * 255); //apply gamma correction table values r_byte = pgm_read_byte(&gamma8[r_byte]); g_byte = pgm_read_byte(&gamma8[g_byte]); b_byte = pgm_read_byte(&gamma8[b_byte]); char key = keypad.getkey(); if (key!= NO_KEY){ // a key has been pressed Serial.print("key: "); Serial.println(key); int neokey = key - '0'; //terminate w zero so don't get ASCII code //enter with '#' if(key == '#'){ neosegment.clearall(); delay(35); neosegment.setsegment(5, 2, 40, 40, 40); neosegment.setsegment(5, 6, 40, 40, 40); delay(35); tone(a1, 660, 100); for(int i = 5; i > -1; i--){ //from right to left neosegment.setsegment(i, 1, 40, 40, 40); neosegment.setsegment(i, 5, 40, 40, 40); delay(35); tone(a1, 660, 100); } neosegment.setsegment(0, 0, 40, 40, 40); neosegment.setsegment(0, 4, 40, 40, 40); tone(a1, 660, 100); neocounter = 0; //letters that appear in upper: A, E, F, H, I, J, L, P, S, U //letters that appear in lower: b, c, d, g, n, o, q, r, t delay(1000); neosegment.clearall(); delay(1000); neosegment.setdigit(5, 'a', 23, 0, 12); tone(a1, 220, 100); delay(500); neosegment.setdigit(4, 'a', 23, 0, 12); neosegment.setdigit(5, 'c', 23, 0, 12); tone(a1, 220, 100); delay(500); neosegment.setdigit(3, 'a', 23, 0, 12); neosegment.setdigit(4, 'c', 23, 0, 12); neosegment.setdigit(5, 'o', 23, 0, 12); tone(a1, 220, 100); delay(500); neosegment.setdigit(2, 'a', 23, 0, 12); neosegment.setdigit(3, 'c', 23, 0, 12); neosegment.setdigit(4, 'o', 23, 0, 12); neosegment.setdigit(5, 'r', 23, 0, 12); tone(a1, 220, 100); delay(500); neosegment.setdigit(1, 'a', 23, 0, 12); neosegment.setdigit(2, 'c', 23, 0, 12); Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 44 of 49

neosegment.setdigit(3, 'o', 23, 0, 12); neosegment.setdigit(4, 'r', 23, 0, 12); neosegment.setdigit(5, 'n', 23, 0, 12); tone(a1, 220, 100); delay(2000); } for(int x=0; x<50; x++){ neosegment.setdigit(2, 'c', 0, x, 0); delay(15); } for(int x=0; x<50; x++){ neosegment.setdigit(4, 'r', x, x, 0); delay(15); } for(int x=0; x<50; x++){ neosegment.setdigit(3, 'o', 0, x, x); delay(15); } for(int x=0; x<50; x++){ neosegment.setdigit(5, 'n', x, 0, 0); delay(15); } for(int x=0; x<50; x++){ neosegment.setdigit(1, 'A', x/2, x/2, x/2); delay(15); } delay(500); neosegment.setdigit(1, 'a', 23, 0, 12); neosegment.setdigit(2, 'c', 23, 0, 12); neosegment.setdigit(3, 'o', 23, 0, 12); neosegment.setdigit(4, 'r', 23, 0, 12); neosegment.setdigit(5, 'n', 23, 0, 12); tone(a1, 220, 100); delay(1700); neosegment.clearall(); delay(500); for(int i = 0; i < 6; i++){ //turn on green lines, middle row, L to R neosegment.setsegment(i, 3, 0, 40, 0); //the '3' segment is middle dash //tone(a1, 440, 100); delay(100); } //special function with '*' else if(key == '*'){ //show HUE value neosegment.clearall(); neosegment.setdigit(0, 'h', 0, 30, 0); neosegment.setdigit(1, 'u', 0, 30, 0); neosegment.setdigit(2, 'e', 0, 30, 0); int ones = (((int)knobhue) % 10); int tens = ((((int)knobhue)/10) % 10); int hundreds = ((((int)knobhue)/100) % 10); neosegment.setdigit(5, ones, r_byte, g_byte, b_byte); neosegment.setdigit(4, tens, r_byte, g_byte, b_byte); neosegment.setdigit(3, hundreds, r_byte, g_byte, b_byte); Serial.print("red byte: "); Serial.println(r_byte); Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 45 of 49

Serial.println(r_byte); } tone(a1, ((knobhue+31)), 200); neocounter = 0; } //number keys else{ // display numbers if(neocounter%6 == 0){ //clear when screen gets full neosegment.clearall(); } int neoposition = (neocounter % 6); //use modulo operation to loop //through the positions int BLUE = knobuppermapped; neosegment.setdigit(neoposition, neokey, r_byte, g_byte, b_byte); neocounter++; tone(a1, ((knobuppermapped * neokey) + 31), 170); //+31 deals with //the 0 key } } //function to convert Hue, Saturation, Value to Red, Green, Blue void HSVtoRGB(float *r, float *g, float *b, float h, float s, float v){ //HSV is in HUE: degrees, SATURATION: 0 to 1.0, VALUE: 0 to 1.0 int i; float f, p, q, t; if( s == 0 ) { // achromatic (grey) *r = *g = *b = v; return; } h /= 60; // sector 0 to 5 i = floor( h ); f = h - i; // factorial part of h p = v * ( 1 - s ); q = v * ( 1 - s * f ); t = v * ( 1 - s * ( 1 - f ) ); switch( i ) { case 0: *r = v; *g = t; *b = p; break; case 1: *r = q; *g = v; *b = p; break; case 2: *r = p; *g = v; *b = t; break; case 3: *r = p; *g = q; *b = v; break; case 4: Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 46 of 49

} *r = t; *g = p; *b = v; break; default: // case 5: *r = v; *g = p; *b = q; break; } You can see from the code that there are a few different functions, depending on which buttons you press. The number keys will display numbers and play beeps, which differ in pitch depending on the digit. Also, turn the upper knob to change which hue will be used the next time you press a number. The bottom knob adjusts value/brightness Press the '*' key to see the hue value expressed as a number from 0-360 on a color wheel Press the '#' key to "enter" your code. This is just a demo mode, so all answers are correct and lead to a short reveal of a new code word. Look at how this was written to adjust for your own needs Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 47 of 49

Adafruit Industries https://learn.adafruit.com/mystery-box-neomatrix-mk-i Page 48 of 49