Skip to content

Commit 8961987

Browse files
committed
feat(lcd1602): add pins + labels
add a new `pins` property which accepts the following values: * "full" - display all 16 pins (default) * "i2c" - display 4 I²C pins * "none" - no pins are displayed (like before)
1 parent 49c2b78 commit 8961987

File tree

2 files changed

+77
-10
lines changed

2 files changed

+77
-10
lines changed

src/lcd1602-element.stories.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,35 @@ storiesOf('LCD1602', module)
6969
)
7070
.add(
7171
'Font A02',
72-
() => html`
73-
<wokwi-lcd1602
74-
.characters="${encode(text('value', symbols))}"
75-
.font=${fontA02}
76-
.cursor=${boolean('cursor', false)}
77-
.blink=${boolean('blink', false)}
78-
cursorX=${number('cursorX', 0, { min: 0, max: 15 })}
79-
cursorY=${number('cursorY', 0, { min: 0, max: 1 })}
80-
></wokwi-lcd1602>
81-
`
72+
() =>
73+
html`
74+
<wokwi-lcd1602
75+
.characters="${encode(text('value', symbols))}"
76+
.font=${fontA02}
77+
.cursor=${boolean('cursor', false)}
78+
.blink=${boolean('blink', false)}
79+
cursorX=${number('cursorX', 0, { min: 0, max: 15 })}
80+
cursorY=${number('cursorY', 0, { min: 0, max: 1 })}
81+
></wokwi-lcd1602>
82+
`
83+
)
84+
.add(
85+
'I²C pins',
86+
() =>
87+
html`
88+
<wokwi-lcd1602
89+
.characters="${encode('I only need 4 pins!')}"
90+
pins="i2c"
91+
></wokwi-lcd1602>
92+
`
93+
)
94+
.add(
95+
'No pins',
96+
() =>
97+
html`
98+
<wokwi-lcd1602
99+
.characters="${encode('Look ma! I got no pins')}"
100+
pins="none"
101+
></wokwi-lcd1602>
102+
`
82103
);

src/lcd1602-element.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class LCD1602Element extends LitElement {
2323
@property() cursorX = 0;
2424
@property() cursorY = 0;
2525
@property() backlight = true;
26+
@property() pins: 'full' | 'i2c' | 'none' = 'full';
2627

2728
static get styles() {
2829
return css`
@@ -102,6 +103,41 @@ export class LCD1602Element extends LitElement {
102103
return result;
103104
}
104105

106+
renderI2CPins() {
107+
return svg`
108+
<rect x="7.55" y="-2.5" height="2.5" width="10.16" fill="url(#pins)" transform="rotate(90)" />
109+
<text y="6.8" x="0.7" fill="white">1</text>
110+
<text y="8.9" x="2.3" fill="white">GND</text>
111+
<text y="11.4" x="2.3" fill="white">VCC</text>
112+
<text y="14" x="2.3" fill="white">SDA</text>
113+
<text y="16.6" x="2.3" fill="white">SCL</text>
114+
`;
115+
}
116+
117+
renderPins() {
118+
return svg`
119+
<rect x="7.55" y="33.5" height="2.5" width="40.64" fill="url(#pins)" />
120+
<text x="6" y="35.3" fill="white">1</text>
121+
<text x="7.2" y="33.3" fill="white">VSS</text>
122+
<text x="9.9" y="33.3" fill="white">VDD</text>
123+
<text x="12.7" y="33.3" fill="white">V0</text>
124+
<text x="15.2" y="33.3" fill="white">RS</text>
125+
<text x="17.8" y="33.3" fill="white">RW</text>
126+
<text x="20.8" y="33.3" fill="white">E</text>
127+
<text x="22.7" y="33.3" fill="white">D0</text>
128+
<text x="25.3" y="33.3" fill="white">D1</text>
129+
<text x="27.9" y="33.3" fill="white">D2</text>
130+
<text x="30.4" y="33.3" fill="white">D3</text>
131+
<text x="33" y="33.3" fill="white">D4</text>
132+
<text x="35.6" y="33.3" fill="white">D5</text>
133+
<text x="38.2" y="33.3" fill="white">D6</text>
134+
<text x="40.8" y="33.3" fill="white">D7</text>
135+
<text x="43.6" y="33.3" fill="white">A</text>
136+
<text x="46.2" y="33.3" fill="white">K</text>
137+
<text x="48" y="35.3" fill="white">16</text>
138+
`;
139+
}
140+
105141
render() {
106142
const { color, characters, background } = this;
107143

@@ -117,6 +153,7 @@ export class LCD1602Element extends LitElement {
117153
height="36mm"
118154
version="1.1"
119155
viewBox="0 0 80 36"
156+
style="font-size: 1.5px; font-family: monospace"
120157
xmlns="http://www.w3.org/2000/svg"
121158
>
122159
<defs>
@@ -130,11 +167,20 @@ export class LCD1602Element extends LitElement {
130167
>
131168
<rect width="2.95" height="5.55" fill-opacity="0.05" />
132169
</pattern>
170+
<pattern id="pins" width="2.54" height="3.255" patternUnits="userSpaceOnUse" y="1.1">
171+
<path
172+
fill="#92926d"
173+
d="M0,0.55c0,0 0.21,-0.52 0.87,-0.52 0.67,0 0.81,0.51 0.81,0.51v1.81h-1.869z"
174+
/>
175+
<circle r="0.45" cx="0.827" cy="0.9" color="black" />
176+
</pattern>
133177
</defs>
134178
<rect width="80" height="36" fill="#087f45" />
135179
<rect x="4.95" y="5.7" width="71.2" height="25.2" />
136180
<rect x="7.55" y="10.3" width="66" height="16" rx="1.5" ry="1.5" fill="${actualBgColor}" />
137181
<rect x="7.55" y="10.3" width="66" height="16" rx="1.5" ry="1.5" opacity="${darken}" />
182+
${this.pins === 'i2c' ? this.renderI2CPins() : null}
183+
${this.pins === 'full' ? this.renderPins() : null}
138184
<rect x="12.45" y="12.55" width="56.2" height="11.5" fill="url(#characters)" />
139185
<path d="${this.path(characters)}" transform="translate(12.45, 12.55)" fill="${color}" />
140186
${this.renderCursor()}

0 commit comments

Comments
 (0)