1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-23 16:16:13 +01:00
CommandStation-EX/Release_Notes/TM1638.md

85 lines
3.7 KiB
Markdown
Raw Normal View History

Squashed commit of the following: commit f13824164b853b2fec66f67b7f3296e2264a861b Author: Asbelos <asbelos@btinternet.com> Date: Thu Oct 10 16:07:42 2024 +0100 _s7 keyword generator commit 8a7dc2643cd15a6d55dd1f257c4940d4167702fc Author: Asbelos <asbelos@btinternet.com> Date: Mon Oct 7 10:54:05 2024 +0100 comments commit 801cddfef70a5ced01da9f022d4b0ad603264e0a Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:24:07 2024 +0100 simpler macro insert commit 5883f474ee79274aaeca94aee13b2235accddbd6 Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:18:29 2024 +0100 Auto include commit 312fc255e4eb8aa4f77dcedbe7206aca22e00af6 Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 13:12:51 2024 +0100 Cleanup to one class commit 309407434928f14f22fef1ff2cdd0f29238f33fb Author: Asbelos <asbelos@btinternet.com> Date: Sun Oct 6 10:34:16 2024 +0100 peeled back commit aa2a6ad1191dbcd6ed75416d457e47b68373277d Author: Asbelos <asbelos@btinternet.com> Date: Sat Oct 5 18:27:43 2024 +0100 all fastpins commit 931baf4b6d4d5b4d55389a64efd5885eeb2218ff Author: Asbelos <asbelos@btinternet.com> Date: Sat Oct 5 16:28:03 2024 +0100 Partial lib extract commit 47bc3b55fc2259cbec9ab830850ea07044ef66be Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 15:41:51 2024 +0100 fixes and SEG7 macro commit 3f26ca2d1a39203428de60cb27f31008847c4233 Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 14:33:23 2024 +0100 enums for exrail easy commit 7e7c00594bf34ebfc331485befc9feaf66cc32ff Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 13:16:57 2024 +0100 Working commit fc4df878482ee3eca6e1232a1ed49ac0c06d2a55 Author: Asbelos <asbelos@btinternet.com> Date: Fri Oct 4 09:27:46 2024 +0100 leds and buttons
2024-10-10 20:38:35 +02:00
## TM1638 ##
The TM1638 board provides a very cheap way of implementing 8 buttons, 8 leds and an 8 digit 7segment display in a package requiring just 5 Dupont wires (vcc, gnd + 3 GPIO pins) from the command station without soldering.
This is ideal for prototyping and testing, simulating sensors and signals, displaying states etc. For a built layout, this could provide a control for things that are not particularly suited to throttle 'route' buttons, perhaps lineside automations or fiddle yard lane selection.
By adding a simple HAL statement to myAutomation.h it creates 8 buttons/sensors and 8 leds.
`HAL(TM1638,500,29,31,33)`
Creates VPINs 500-507 And desscribes the GPIO pins used to connect the clk,dio,stb pins on the TM1638 board.
Setting each of the VPINs will control the associated LED (using for example SET, RESET or BLINK in Exrail or `<z 500> <z -501> from a command).
Unlike most pins, you can also read the same pin number and get the button state, using Exrail IF/AT/ONBUTTON etc.
For example:
`
HAL(TM1638,500,29,31,33)
`
All the folowing examples assume you are using VPIN 500 as the first, leftmost, led/button on the TM1638 board.
`ONBUTTON(500)
SET(500) // light the first led
BLINK(501,500,500) // blink the second led
SETLOCO(3) FWD(50) // set a loco going
AT(501) STOP // press second button to stop
RESET(500) RESET(501) // turn leds off
DONE
`
Buttons behave like any other sensor, so using `<S 500 500 1>` will cause the command station to issue `<Q 500>` and `<q 500>` messages when the first button is pressed or released.
Exrail `JMRI_SENSOR(500,8)` will create `<S` commands for all 8 buttons.
## Using the 7 Segment display ##
The 8 digit display can be treated as 8 separate digits (left most being the same VPIN as the leftmost button and led) or be written to in sections of any length. Writing uses the existing analogue interface to the common HAL but is awkward to use directly. To make this easier from Exrail, a SEG7 macro provides a remapping to the ANOUT facility that makes more sense.
SEG7(vpin,value,format)
The vpin determins which digit to start writing at.
The value can be a 32bit unsigned integer but is interpreted differentlky according to the format.
Format values:
1..8 give the length (number of display digits) to fill, and defaults to decimal number with leading zeros.
1X..8X give the length but display in hex.
1R..4R treats each byte of the value as raw 7-segment patterns so that it can write letters and symbols using any compination of the 7segments and deciml point.
There is a useful description here:
https://jetpackacademy.com/wp-content/uploads/2018/06/TM1638_cheat_sheet_download.pdf
e.g. SEG7(500,3,4)
writes 0003 to first 4 digits of the display
SEG7(504,0xcafe,4X)
writes CAFE to the last 4 digits
SEG7(500,0xdeadbeef,8X)
writes dEAdbEEF to all 8 digits.
Writing raw segment patters requires knowledge of the bit pattern to segment relationship:
` 0
== 0 ==
5| | 1
== 6 ==
4 | | 2
== 3 ==
7=decimal point
Thus Letter A is segments 6 5 4 2 1 0, in bits that is (0 bit on right)
0b01110111 or 0x77
This is not easy to do my hand and thus a new string type suffix has been introduced to make simple text messages. Note that the HAL interface only has width for 32 bits which is only 4 symbols so writing 8 digits requires two calls.
e.g. SEG7(500,"Hell"_s7,4R) SEG7(504,"o"_s7,4R)
DELAY(1000)
SEG7(500,"Worl"_s7,4R) SEG7(504,"d"_s7,4R)
Note that some letters like k,m,v,x do not have particularly readable 7-segment representations.
Credit to https://github.com/dvarrel/TM1638 for the basic formulae.