sourceextensions/blender/demos/KeysRun.xtl

1⍝│ KeysRun.xtl -- HEX1000-keys-leds: the complete Nano 1K calculator 2⍝│ driven by physical contacts, from checked board simulation. Geometry 3⍝│ and animation keys are X_eTaL arrays. The keypad/display layout is 4⍝│ the pinned Panel library's scene units, not measured dimensions. 5⍝│ Import: "kr:" u_se< "KeysRun" 6"vd:" u̲se< "Video" 7"pn:" u̲se< "Panel" 8"fr:" u̲se< "Front" 9 10⍝│ title: the physical-key Nano 1K video family 11ˡtitle ← "HEX1000-keys-leds" 12⍝│ subtitle: the source of every animated value 13ˡsubtitle ← "physical keys and MAX7219 LEDs on a Tang Nano 1K; full board simulation" 14⍝│ length: video seconds 15ˡlength ← 36.0 16⍝│ frames: seconds sampled at 30 frames per second 17ˡframes ← (f̲loat o̲ffsets 1081) ÷ 30.0 18⍝│ l:m_ap landmarks: actual VCD picoseconds to video seconds, explicit 19⍝│ slow motion for bounce, first-key acceptance and one serial word 20ˡm̲ap ← { points → 21 2 1 t̲ranspose 2 14 r̲eshape (0.0 c̲at f̲loat points) c̲at 0.0 3.0 6.0 8.0 10.0 15.0 16.5 24.0 26.0 26.5 30.0 31.0 34.0 35.0 22} 23⍝│ l:t_imes landmarks: VCD time of each video frame; hold at the end 24ˡt̲imes ← { points → 25 m ← ˡm̲ap points 26 f̲loor (f̲loat f̲irst -1 t̲ake points) m̲in 0.0 m̲ax ((2 1 s̲elect₂ m, ˡframes) ᵛᵈr̲etime 0) 27} 28⍝│ cueTexts: narration and on-screen captions, in chronological order 29ˡcueTexts ← ˡtitle c̲at ": " c̲at ˡsubtitle c̲at "|Startup: the level shifter enables, and real MAX7219 writes light DEADBEEF.|Slow motion: a short bouncing contact is rejected. The startup banner stays.|First key C: rows scan, columns synchronize, eight stable scans accept one press. Holding it does not repeat.|Time-lapse: release between keys. The circuit and X_eTaL agree; C0DE+BEEF= ends at 17FCD.|Slow motion: one actual 16-bit MAX7219 word, DIN sampled on clock rises, LOAD latching the LEDs.|Press equals again: Front translates it to Clear. The physical display returns to zero." 30⍝│ cueTable: start and end of each cue 31ˡcueTable ← 7 2 r̲eshape 0 2.6 2.8 6 6 9.8 10 16.4 16.5 26.4 26.5 30.5 31 36 32 33⍝ Frames by objects to the first state and every changed state. 34ʰs̲teps ← { g → 35 n ← 1 s̲elect s̲hape g 36 m ← 2 s̲elect s̲hape g 37 keep ← r̲avel 2 1 t̲ranspose ((1 c̲at m) r̲eshape 1 = 1) c̲at n̲ot (1 d̲rop g) = -1 d̲rop g 38 obj ← r̲avel 2 1 t̲ranspose (n c̲at m) r̲eshape f̲loat r̲ange m 39 at ← r̲avel (m c̲at n) r̲eshape ˡframes 40 val ← r̲avel 2 1 t̲ranspose f̲loat g 41 k ← '+ r̲/ keep 42 2 1 t̲ranspose (3 c̲at k) r̲eshape (keep r̲eplicate obj) c̲at (keep r̲eplicate at) c̲at keep r̲eplicate val 43} 44ʰl̲it ← { (name, boxes, on) z → 45 ((name, boxes) ᵛᵈb̲oxes 0) c̲at (name, "glow", ʰs̲teps 0.06 + 2.5 × f̲loat on) ᵛᵈs̲teps 0 46} 47ʰs̲trokes ← { (lit, _) → lit } 48ʰb̲oxes ← { (p, dims, color) z → p c̲at₂ (((t̲ally p) c̲at 3) r̲eshape dims) c̲at₂ (((t̲ally p) c̲at 4) r̲eshape color c̲at 0.06) } 49ʰj̲oin ← { a b → e̲nclose (d̲isclose a) c̲at "|" c̲at d̲isclose b } 50 51⍝│ (size, samples, word) l:s_cene 0: schematic panel and Nano 1K, 52⍝│ glows from the checked VCD samples. Samples are time, contacts, 53⍝│ scan/sync/debounce/handshake, machine, serial pins, eight decoded 54⍝│ display registers, stage and actual serial-bit count. 55ˡs̲cene ← { (size, samples, word) z → 56 w ← 1 s̲elect size 57 h ← 2 s̲elect size 58 n ← t̲ally samples 59 ts ← n t̲ake ˡframes 60 d ← (w, h, 35, 13.0, 11.0) ᵛᵈf̲it 0 61 xy ← ᵖⁿk̲eyAt o̲ffsets 20 62 keyAt ← 2 1 t̲ranspose 3 20 r̲eshape ((1 s̲elect₂ xy) − 3.0) c̲at (20 r̲eshape -0.2) c̲at 2 s̲elect₂ xy 63 contacts ← (2 s̲elect₂ samples) + 65536 × 15 − 3 s̲elect₂ samples 64 positions ← (ᶠʳMap i̲ndexOf o̲ffsets 20) − 1 65 down ← (contacts 'd̲iv t̲able 2 ^ positions) m̲od 2 66 legendAt ← (keyAt + 20 3 r̲eshape 0.0 -0.35 0.0) c̲at₂ 20 4 r̲eshape 0.26 245 245 255 67 strokes ← ʰs̲trokes ᵖⁿd̲igits 8 r̲eshape 24 68 lines ← (1 s̲elect₂ strokes) − 3.0 69 segs ← (2 1 t̲ranspose 6 56 r̲eshape lines c̲at (56 r̲eshape -0.25) c̲at (2 s̲elect₂ strokes) c̲at ((3 s̲elect₂ strokes) − 3.0) c̲at (56 r̲eshape -0.25) c̲at 4 s̲elect₂ strokes) c̲at₂ 56 4 r̲eshape 100 250 160 0.025 70 digit ← (o̲ffsets 56) d̲iv 7 71 ⍝ MAX7219 a..g are bits 6..0; the Panel strokes are a..g. 72 dg ← (1 + digit) s̲elect₂ 8 t̲ake₂ 16 d̲rop₂ samples 73 on ← (dg d̲iv ((n c̲at 56) r̲eshape 2 ^ 6 − (o̲ffsets 56) m̲od 7)) m̲od 2 74 rowAt ← 2 1 t̲ranspose 3 4 r̲eshape (4 r̲eshape -5.55) c̲at (4 r̲eshape -0.25) c̲at 0.55 − 0.95 × f̲loat o̲ffsets 4 75 rowOn ← ((4 s̲elect₂ samples) 'd̲iv t̲able 2 ^ o̲ffsets 4) m̲od 2 76 colAt ← 2 1 t̲ranspose 3 4 r̲eshape (-5.0 + 0.95 × f̲loat o̲ffsets 4) c̲at (4 r̲eshape -0.25) c̲at 4 r̲eshape 1.3 77 colOn ← ((15 − 5 s̲elect₂ samples) 'd̲iv t̲able 2 ^ o̲ffsets 4) m̲od 2 78 board ← 3 10 r̲eshape 3.0 0.1 0.9 2.4 0.3 3.4 20 105 70 1 3.0 -0.2 0.9 1.25 0.25 1.25 25 28 40 1 3.0 -0.1 2.3 1.1 0.4 0.5 180 185 200 1 79 t ← ((ᵛᵈhead c̲at ((w, h, 30, ˡlength, 8 10 18, 35) ᵛᵈs̲tage 0)) c̲at 80 ((0.0 36.0, 2 3 r̲eshape 0.0 c̲at (n̲eg d) c̲at 0.0, 2 3 r̲eshape 0.0) ᵛᵈc̲amera 0) c̲at 81 ((("panel", 2 10 r̲eshape -3.0 0.2 0.25 5.5 0.4 6.7 35 45 65 1 -3.0 -0.05 2.3 4.9 0.1 1.1 12 25 18 1) ᵛᵈb̲oxes 0)) c̲at 82 (("keys", (keyAt, 0.78 0.3 0.78, 50 130 210) ʰb̲oxes 0, down) ʰl̲it 0) c̲at 83 (("legends", "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|+|-|*|=", legendAt) ᵛᵈl̲abels 0) c̲at 84 (("segments", segs) ᵛᵈl̲ines 0) c̲at 85 (("segments", "glow", ʰs̲teps 0.04 + 3.0 × f̲loat on) ᵛᵈs̲teps 0) c̲at 86 (("rows", (rowAt, 0.14 0.08 0.14, 255 170 65) ʰb̲oxes 0, rowOn) ʰl̲it 0) c̲at 87 (("columns", (colAt, 0.14 0.08 0.14, 255 170 65) ʰb̲oxes 0, colOn) ʰl̲it 0) c̲at 88 ("Nano 1K", board) ᵛᵈb̲oxes 0) 89 flags ← (6 s̲elect₂ samples) ≠ 0 90 spiAt ← 3 3 r̲eshape 1.7 -0.2 -2.2 3.0 -0.2 -2.2 4.3 -0.2 -2.2 91 spiOn ← 3 t̲ake₂ 12 d̲rop₂ samples 92 texts ← "Nano 1K (schematic)|accepted|DIN|CLK|LOAD|physical contacts / row scan|MAX7219 LEDs" 93 words ← 7 7 r̲eshape 3 -0.6 3.0 0.34 230 235 255 3 -0.6 -1.65 0.25 230 235 255 1.7 -0.6 -2.65 0.23 230 235 255 3 -0.6 -2.65 0.23 230 235 255 4.3 -0.6 -2.65 0.23 230 235 255 -3 -0.6 -3.5 0.28 230 235 255 -3 -0.6 3.3 0.34 230 235 255 94 bitAt ← 2 1 t̲ranspose 3 16 r̲eshape (0.6 + 0.3 × f̲loat o̲ffsets 16) c̲at (16 r̲eshape -0.2) c̲at 16 r̲eshape -3.35 95 bits ← (word d̲iv 2 ^ 15 − o̲ffsets 16) m̲od 2 96 sent ← (26 s̲elect₂ samples) '> t̲able o̲ffsets 16 97 bitOn ← (f̲loat sent) × (n c̲at 16) r̲eshape 0.2 + 0.8 × f̲loat bits 98 withAccepted ← ((t c̲at ("accepted", 1 10 r̲eshape 3.0 -0.3 -1.2 0.25 0.1 0.25 100 250 160 0.06, (n c̲at 1) r̲eshape flags) ʰl̲it 0) c̲at 99 (("SPI pins", (spiAt, 0.22 0.1 0.22, 250 190 70) ʰb̲oxes 0, spiOn) ʰl̲it 0) c̲at 100 (("labels", texts, words) ᵛᵈl̲abels 0) c̲at 101 (("word", (bitAt, 0.23 0.07 0.3, 100 220 250) ʰb̲oxes 0, bitOn) ʰl̲it 0) c̲at 102 ("word", 16 2 r̲eshape 26.5 30.0) ᵛᵈs̲hown 0) 103 clockText ← d̲isclose 'ʰj̲oin r̲/ '{ i → e̲nclose (3 ᵛᵈf̲ixed (f̲loat i s̲elect 1 s̲elect₂ samples) ÷ 1000000000.0) c̲at " ms A " c̲at (f̲ormat i s̲elect 10 s̲elect₂ samples) c̲at " PC " c̲at (f̲ormat i s̲elect 11 s̲elect₂ samples) c̲at " stable " c̲at f̲ormat i s̲elect 7 s̲elect₂ samples } e̲ach r̲ange n 104 ((withAccepted c̲at ("state", 0.0 0.84 0.09 255 230 150, clockText, ts) ᵛᵈr̲eadout 0) c̲at 105 (((ˡtitle, ˡsubtitle, 1 8 r̲eshape 0 2.6 255 255 255 18 22 44) ᵛᵈc̲ards 0)) c̲at 106 (ˡcueTexts, ˡcueTable c̲at₂ 7 3 r̲eshape 255 255 255) ᵛᵈc̲aptions 0) 107}