Skip to content

Commit b441af3

Browse files
committed
feat(lcd1602): fonts from the HD44780 datasheet
Added A00 and A02 fonts
1 parent cab4a7d commit b441af3

File tree

6 files changed

+541
-262
lines changed

6 files changed

+541
-262
lines changed

src/font8x5.ts

Lines changed: 0 additions & 259 deletions
This file was deleted.

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export { PushbuttonElement } from './pushbutton-element';
33
export { ResistorElement } from './resistor-element';
44
export { SevenSegmentElement } from './7segment-element';
55
export { LCD1602Element, ICursorType } from './lcd1602-element';
6+
export { fontA00 } from './lcd1602-font-a00';
7+
export { fontA02 } from './lcd1602-font-a02';

src/lcd1602-element.stories.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { withKnobs, text, select, number } from '@storybook/addon-knobs';
22
import { storiesOf } from '@storybook/web-components';
33
import { html } from 'lit-html';
4+
import { fontA02 } from './lcd1602-font-a02';
45
import './lcd1602-element';
56

67
const encode = (s: string) => new Uint8Array(s.split('').map(c => c.charCodeAt(0)));
78
const helloWorld = 'Hello, World!';
9+
const symbols = '\x10 I \x9d Symbols! \x11\xab \x14\x18\x17\x1e \x91\x98\x96 \x93\x97\xa9 \xbb';
810

911
storiesOf('LCD1602', module)
1012
.addDecorator(withKnobs)
@@ -51,4 +53,16 @@ storiesOf('LCD1602', module)
5153
cursorY="1"
5254
></wokwi-lcd1602>
5355
`
56+
)
57+
.add(
58+
'Font A02',
59+
() => html`
60+
<wokwi-lcd1602
61+
.characters="${encode(text('value', symbols))}"
62+
.font=${fontA02}
63+
cursor=${select('cursor', ['off', 'blink', 'underline'], 'off')}
64+
cursorX=${number('cursorX', 0, { min: 0, max: 15 })}
65+
cursorY=${number('cursorY', 0, { min: 0, max: 1 })}
66+
></wokwi-lcd1602>
67+
`
5468
);

src/lcd1602-element.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { customElement, html, LitElement, property, css, svg } from 'lit-element';
2-
import { font8x5 } from './font8x5';
2+
import { fontA00 } from './lcd1602-font-a00';
33

44
export type ICursorType = 'off' | 'blink' | 'underline';
55

@@ -16,7 +16,7 @@ export class LCD1602Element extends LitElement {
1616
@property() color = 'black';
1717
@property() background = 'green';
1818
@property({ type: Array }) characters: number[] | Uint8Array = new Uint8Array(32);
19-
@property() font = font8x5;
19+
@property() font = fontA00;
2020
@property() cursor: ICursorType = 'off';
2121
@property() cursorX = 0;
2222
@property() cursorY = 0;
@@ -55,7 +55,7 @@ export class LCD1602Element extends LitElement {
5555
for (let py = 0; py < 8; py++) {
5656
const row = this.font[characters[i] * 8 + py];
5757
for (let px = 0; px < 5; px++) {
58-
if (row & (1 << (7 - px))) {
58+
if (row & (1 << px)) {
5959
const x = (charX + px * xSpacing).toFixed(2);
6060
const y = (charY + py * ySpacing).toFixed(2);
6161
result.push(`M ${x} ${y}h0.55v0.65h-0.55Z`);

0 commit comments

Comments
 (0)