It is NOT true that I lay awake at night thinking of odd things to do with the NeoTrinkey*....
That said, here's a project I've been thinking about for a while - making an RPN calculator (well more of an adding machine) with the NeoTrinkey.
The project code is here and consists of two CircuitPython modules, babbage.py (renamed to code.py when in use) and a helper module, ncount.py.
One of the great features of the NeoTrinkey is the four neopixels - they provide a very flexible output display. Considering the range of colors you could present with the neopixels, you could easily represent any number from 0 to 999 (assuming ten colors). For this project, we're sticking to binary and using the ncount.py function binnum(color, number) - it will display the values from 0-15, using the neopixels:
Given a number, binnum(color,num) will display the binary value from 0-15 (for zero all pixels are set to faint white; otherwise the pixels are set to color for the value of num.).
So... how to use this for a calculator?
I defined an array to be a stack, then set four states for the calculator: wait, enter, add, subtract, and pop.
To toggle between states, one touches the#1 pad. When you do you'll see the current state appear (and clear) with the color "gold.":
STATE
Wait - a do-nothing state
Enter - Use to enter values in the stack. Touch pad #2 until you see the desired value appear in green pixels. Touch #1 again to "enter" the value in the stack. It will appear in blue. You can resume touching pad #2 to enter another number - as many as you want. Touch #1 a second time to resume choosing the state.
Add - Touch pad #2 and it will pop the two top values from the stack, add them together and push the result back on the stack. If you have a lot of numbers, you can do this multiple times.
Subtract - Touch pad #2 to pop the two top values off the stack. The first value will be subtracted from the second and pushed back on the stack. Again, if the stack has a lot of values, you can repeat until you touch pad #1.
POP - Touch pad #2 to pop off and display the top value on the stack. Repeated to clear as many values as you want.
Important: For this project, the math performed is modular arithmetic, sometimes called "clock arithmetic." As Wikipedia explains: In mathematics, modular arithmetic is a system of arithmetic for integers, where numbers "wrap around" when reaching a certain value, called the modulus.
Load babbage.py as code.py and add ncount.py to your NeoTrinkey and you can run this anywhere the Trinkey can get power - no computer or IDE required. However, if you plug it into a computer running Mu as your IDE, you can see the steps in the REPL.
For example:
code.py | 9.1.1\]0;🐍code.py | 9.1.1\current state: enter
current state: add
current state: subtract
current state: pop
current state: wait
current state: enter
val: 1
val: 2
val: 3
val: 1
val: 2
val: 3
val: 4
val: 5
val: 6
val: 6
val: 6
val: 6
val: 6
current state: add
adding 6 + 3 = 9
current state: subtract
current state: pop
current state: wait
current state: enter
val: 1
val: 2
current state: add
current state: subtract
subtracting 9 - 2 = 7
I certainly don't think this has a lot of practical applications or will replace your scientific calculator, but it was a fun experiment and gave me some ideas about building a user interface around the two Neo Trinkey touch pads - maybe you'll think of some more...
------------------------
* While I don't lie awake dreaming of crazy projects, I will admit to going to sleep dreaming of new things to squeeze out of the NeoTrinkey. Beats counting sheep.
This page (NeoTrinkey RRPN Calculator (The extra "R" is for "Ridiculous")) was last updated on August 30, 2024.
Text editor powered by tinymce.