Skip to content

Commit cf9e657

Browse files
committed
feat(lcd1602): backlight support
1 parent b441af3 commit cf9e657

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lcd1602-element.stories.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { withKnobs, text, select, number } from '@storybook/addon-knobs';
1+
import { withKnobs, text, select, number, boolean } from '@storybook/addon-knobs';
22
import { storiesOf } from '@storybook/web-components';
33
import { html } from 'lit-html';
44
import { fontA02 } from './lcd1602-font-a02';
@@ -18,6 +18,7 @@ storiesOf('LCD1602', module)
1818
cursor=${select('cursor', ['off', 'blink', 'underline'], 'off')}
1919
cursorX=${number('cursorX', 0, { min: 0, max: 15 })}
2020
cursorY=${number('cursorY', 0, { min: 0, max: 1 })}
21+
.backlight=${boolean('backlight', true)}
2122
></wokwi-lcd1602>
2223
`
2324
)
@@ -54,6 +55,18 @@ storiesOf('LCD1602', module)
5455
></wokwi-lcd1602>
5556
`
5657
)
58+
.add(
59+
'Display off (green)',
60+
() => html`
61+
<wokwi-lcd1602 .backlight=${false}></wokwi-lcd1602>
62+
`
63+
)
64+
.add(
65+
'Display off (blue)',
66+
() => html`
67+
<wokwi-lcd1602 .backlight=${false} color="white" background="blue"></wokwi-lcd1602>
68+
`
69+
)
5770
.add(
5871
'Font A02',
5972
() => html`

src/lcd1602-element.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class LCD1602Element extends LitElement {
2020
@property() cursor: ICursorType = 'off';
2121
@property() cursorX = 0;
2222
@property() cursorY = 0;
23+
@property() backlight = true;
2324

2425
static get styles() {
2526
return css`
@@ -96,6 +97,7 @@ export class LCD1602Element extends LitElement {
9697
render() {
9798
const { color, characters, background } = this;
9899

100+
const darken = this.backlight ? 0 : 0.5;
99101
const actualBgColor =
100102
background in backgroundColors ? backgroundColors[background] : backgroundColors;
101103

@@ -124,6 +126,7 @@ export class LCD1602Element extends LitElement {
124126
<rect width="80" height="36" fill="#087f45" />
125127
<rect x="4.95" y="5.7" width="71.2" height="25.2" />
126128
<rect x="7.55" y="10.3" width="66" height="16" rx="1.5" ry="1.5" fill="${actualBgColor}" />
129+
<rect x="7.55" y="10.3" width="66" height="16" rx="1.5" ry="1.5" opacity="${darken}" />
127130
<rect x="12.45" y="12.55" width="56.2" height="11.5" fill="url(#characters)" />
128131
<path d="${this.path(characters)}" transform="translate(12.45, 12.55)" fill="${color}" />
129132
${this.renderCursor()}

0 commit comments

Comments
 (0)