[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003cp\u003eIt is NOT true that I lay awake at night thinking of odd things to do with the NeoTrinkey*....\u003c/p\u003e\n\u003cp\u003eThat 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.\u003c/p\u003e\n\u003cp\u003eThe project code is \u003ca href=\"https://github.com/mrklingon/RRPN-Calculator\" target=\"_blank\"\u003ehere\u003c/a\u003e\u0026nbsp;and consists of two CircuitPython modules, babbage.py (renamed to code.py when in use) and a helper module, ncount.py.\u003c/p\u003e\n\u003cp\u003eOne of the great features of the NeoTrinkey is the four neopixels - they provide a very flexible output display. Considering the range of colors you\u0026nbsp;\u003cem\u003ecould\u003c/em\u003e 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\u0026nbsp;\u003cstrong\u003ebinnum(color, number)\u003c/strong\u003e - it will display the values from 0-15, using the neopixels:\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/125/original/binary.jpg?1725065495","metadata":{"caption":"binary values"}},{"element_type":"text","content":"\n  \n  \n        \u003cp\u003eGiven 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 \u003cem\u003ecolor\u003c/em\u003e for the value of num.).\u003c/p\u003e\n\u003cp\u003eSo... how to use this for a calculator?\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eI defined an array to be a stack, then set four states for the calculator:\u0026nbsp;\u003cem\u003ewait, enter, add, subtract,\u0026nbsp;\u003c/em\u003eand\u003cem\u003e pop.\u003c/em\u003e\u003c/p\u003e\n\u003cp\u003eTo toggle between states, one touches the#1 pad. When you do you'll see the current state appear (and clear) with the color \"\u003cstrong\u003egold\u003c/strong\u003e.\":\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n      \n\n","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/001/126/original/states.jpg?1725065927","metadata":{"caption":"RRPN calculator states"}},{"element_type":"text","content":"\n  \n  \n  \n        \u003cp\u003e\u003cspan style=\"text-decoration: underline;\"\u003eSTATE\u003c/span\u003e\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eWait\u003c/strong\u003e\u0026nbsp; - a do-nothing state\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eEnter \u003c/strong\u003e- Use to enter values in the stack. Touch pad #2 until you see the desired value appear in\u0026nbsp;\u003cstrong\u003egreen \u003c/strong\u003epixels. Touch #1 again to \"enter\" the value in the stack. It will appear in \u003cstrong\u003eblue.\u0026nbsp;\u003c/strong\u003eYou can resume touching pad #2 to enter another number - as many as you want. Touch #1 a second time to resume choosing the state.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eAdd \u003c/strong\u003e- 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.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eSubtract -\u0026nbsp;\u003c/strong\u003eTouch 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.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003ePOP\u003c/strong\u003e - Touch pad #2 to pop off and display the top value on the stack. Repeated to clear as many values as you want.\u003c/p\u003e\n\u003cp\u003e\u003cstrong\u003eImportant\u003c/strong\u003e: For this project, the math performed is \u003ca href=\"https://en.wikipedia.org/wiki/Modular_arithmetic\" target=\"_blank\"\u003emodular arithmetic\u003c/a\u003e, sometimes called \"clock arithmetic.\" As Wikipedia explains\u003cem\u003e: In\u0026nbsp;\u003ca title=\"Mathematics\" href=\"https://en.wikipedia.org/wiki/Mathematics\"\u003emathematics\u003c/a\u003e,\u0026nbsp;\u003cstrong\u003emodular arithmetic\u003c/strong\u003e\u0026nbsp;is a system of\u0026nbsp;\u003ca title=\"Arithmetic\" href=\"https://en.wikipedia.org/wiki/Arithmetic\"\u003earithmetic\u003c/a\u003e\u0026nbsp;for\u0026nbsp;\u003ca title=\"Integer\" href=\"https://en.wikipedia.org/wiki/Integer\"\u003eintegers\u003c/a\u003e, where numbers \"wrap around\" when reaching a certain value, called the\u0026nbsp;\u003cstrong\u003emodulus\u003c/strong\u003e.\u0026nbsp;\u003c/em\u003e\u003c/p\u003e\n      \n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n        \u003cp\u003eLoad 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.\u0026nbsp;\u003cem\u003eHowever\u003c/em\u003e, if you plug it into a computer running Mu as your IDE, you can see the steps in the REPL.\u003c/p\u003e\n\u003cp\u003eFor example:\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecode.py | 9.1.1\\]0;🐍code.py | 9.1.1\\current state: enter\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: add\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: subtract\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: pop\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: wait\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: enter\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 1\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 2\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 3\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 40px;\"\u003e\u0026nbsp; \u0026nbsp; \u0026nbsp; \u003ccode\u003eval: 1\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 2\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 3\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 4\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 5\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 6\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 6\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 6\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 6\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 6\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: add\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eadding 6 + 3 = 9\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: subtract\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: pop\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: wait\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: enter\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 1\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003eval: 2\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: add\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003ecurrent state: subtract\u003c/code\u003e\u003c/p\u003e\n\u003cp style=\"padding-left: 80px;\"\u003e\u003ccode\u003esubtracting 9 - 2 = 7\u003c/code\u003e\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n      \n","metadata":{}},{"element_type":"text","content":"\n        \u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003eI 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...\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e\u0026nbsp;\u003c/p\u003e\n\u003cp\u003e------------------------\u003c/p\u003e\n\u003cp\u003e* While I\u0026nbsp;\u003cem\u003edon't\u003c/em\u003e lie awake dreaming of crazy projects, I\u0026nbsp;\u003cem\u003ewill\u003c/em\u003e admit to going to sleep\u0026nbsp;\u003cem\u003edreaming\u003c/em\u003e of new things to squeeze out of the NeoTrinkey. Beats counting sheep.\u003c/p\u003e\n      ","metadata":{}}]