PLED display
Door Luc Zontrop, 20 jaar geleden, 6.121x bekeken
Code en image aangepast. 1lijn, kleine letters toegevoegd.
Met dit scriptje kun je een PLED- display simulatie nabootsen. 'k heb de standaard fontset toegevoegd.
Voorbeeldje kan ik niet laten zien, enkel een screenshot.
Zip file met alles vind je hier: http://users.telenet.be/tumbler/pled.zip
voorbeelden:
HIER
HIER
Have fun.
Gesponsorde koppelingen
PHP script bestanden
Er zijn 25 reacties op 'Pled display'
Gesponsorde koppelingen
Hehe grappig. Die mega array kan je gewoon vergelijken als bitmaps?
Edit:
Hehe, ik ging ook ff een tekentje creëren:
124=> array("00000","00000","01010","10101","10001","01010","00100","00000")
Kun je hartjes doen met '|'
zie hier
Edit:
Hehe, ik ging ook ff een tekentje creëren:
124=> array("00000","00000","01010","10101","10001","01010","00100","00000")
Kun je hartjes doen met '|'
zie hier
Ik heb um omgebouwd naar een klasse, wou ook kleine letters toevoegen maar kan die codes niet vinden...
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* PLED
* Met dit scriptje kun je een PLED- display simulatie nabootsen.
* Ik heb de standaard fontset toegevoegd (enkel hoofdletters).
* Kleine letter kun je gemakkelijk toevoegen. Zorg voor de juiste ascii waarde die je meegeeft in de keys.
* @author Tumbler
*/
class PLED {
private $chars = array(
# 32 -> 47: Zie ascii tabel
32 => array("00000","00000","00000","00000","00000","00000","00000","00000"), # space
33 => array("00100","00100","00100","00100","00100","00000","00100","00000"), # !
34 => array("01010","01010","01010","00000","00000","00000","00000","00000"), # "
35 => array("01010","01010","11111","01010","11111","01010","01010","00000"), # #
36 => array("00100","01111","10100","01110","00101","11110","00100","00000"), # $
37 => array("11000","11001","00010","00100","01000","10011","00011","00000"), # %
38 => array("01100","10010","10100","01000","10101","10010","01101","00000"), # &
39 => array("01100","00100","01000","00000","00000","00000","00000","00000"), # '
40 => array("00010","00100","01000","01000","01000","00100","00010","00000"), # (
41 => array("01000","00100","00010","00010","00010","00100","01000","00000"), # )
42 => array("00000","00100","10101","01110","10101","00100","00000","00000"), # *
43 => array("00000","00100","00100","11111","00100","00100","00000","00000"), # +
44 => array("00000","00000","00000","00000","01100","00100","01000","00000"), # ,
45 => array("00000","00000","00000","11111","00000","00000","00000","00000"), # -
46 => array("00000","00000","00000","00000","00000","01100","01100","00000"), # .
47 => array("00000","00001","00010","00100","01000","10000","00000","00000"), # /
# 48 -> 57: 0 - 9
48 => array("01110","10001","10011","10101","11001","10001","01110","00000"), # 0
49 => array("00100","01100","00100","00100","00100","00100","11111","00000"), # 1
50 => array("01110","10001","00001","00010","00100","01000","11111","00000"), # 2
51 => array("11111","00010","00100","00010","00001","10001","01110","00000"), # 3
52 => array("00010","00110","01010","10010","11111","00010","00010","00000"), # 4
53 => array("11111","10000","11110","00001","00001","10001","01110","00000"), # 5
54 => array("00110","01000","10000","11110","10001","10001","01110","00000"), # 6
55 => array("11111","00001","00010","00100","01000","01000","01000","00000"), # 7
56 => array("01110","10001","10001","01110","10001","10001","01110","00000"), # 8
57 => array("01110","10001","10001","01111","00001","00010","01100","00000"), # 9
# 58 -> 64: Zie ascii tabel
58 => array("00000","01100","01100","00000","01100","01100","00000","00000"), # :
59 => array("00000","01100","01100","00000","01100","00100","01000","00000"), # ;
60 => array("00010","00100","01000","10000","01000","00100","00010","00000"), # <
61 => array("00000","00000","11111","00000","11111","00000","00000","00000"), # =
62 => array("01000","00100","00010","00001","00010","00100","01000","00000"), # >
63 => array("01110","10001","00001","00010","00100","00000","00100","00000"), # ?
64 => array("01110","10001","00001","01101","10101","10101","01110","00000"), # @
# 65 -> 90: A - Z
65 => array("01110","10001","10001","11111","10001","10001","10001","00000"), # A
66 => array("11110","10001","10001","11110","10001","10001","11110","00000"), # B
67 => array("01110","10001","10000","10000","10000","10001","01110","00000"), # C
68 => array("11110","10001","10001","10001","10001","10001","11110","00000"), # D
69 => array("11111","10000","10000","11110","10000","10000","11111","00000"), # E
70 => array("11111","10000","10000","11110","10000","10000","10000","00000"), # F
71 => array("01110","10001","10000","10111","10001","10001","01111","00000"), # G
72 => array("10001","10001","10001","11111","10001","10001","10001","00000"), # H
73 => array("01110","00100","00100","00100","00100","00100","01110","00000"), # I
74 => array("00111","00010","00010","00010","00010","10010","01100","00000"), # J
75 => array("10001","10010","10100","11000","10100","10010","10001","00000"), # K
76 => array("10000","10000","10000","10000","10000","10000","11111","00000"), # L
77 => array("10001","11011","10101","10001","10001","10001","10001","00000"), # M
78 => array("10001","10001","11001","10101","10011","10001","10001","00000"), # N
79 => array("01110","10001","10001","10001","10001","10001","01110","00000"), # O
80 => array("11110","10001","10001","11110","10000","10000","10000","00000"), # P
81 => array("01110","10001","10001","10001","10101","10010","01101","00000"), # Q
82 => array("11110","10001","10001","11110","10100","10010","10001","00000"), # R
83 => array("01110","10001","10000","01110","00001","10001","01110","00000"), # S
84 => array("11111","00100","00100","00100","00100","00100","00100","00000"), # T
85 => array("10001","10001","10001","10001","10001","10001","01110","00000"), # U
86 => array("10001","10001","10001","10001","10001","01010","00100","00000"), # V
87 => array("10001","10001","10001","10001","10101","10101","01010","00000"), # W
88 => array("10001","10001","01010","00100","01010","10001","10001","00000"), # X
89 => array("10001","10001","01010","00100","00100","00100","00100","00000"), # Y
90 => array("11111","00001","00010","00100","01000","10000","11111","00000"), # Z
# 91 -> 98: Zie ascii tabel
91 => array("01110","01000","01000","01000","01000","01000","01110","00000"), # [
92 => array("10001","01010","11111","00100","11111","00100","00100","00000"), # \
93 => array("01110","00010","00010","00010","00010","00010","01110","00000"), # ]
94 => array("00100","01010","10001","00000","00000","00000","00000","00000"), # ^
95 => array("00000","00000","00000","00000","00000","00000","11111","00000"), # _
96 => array(), # `
# 65 -> 90: a - z
97 => array(), # a
98 => array(), # b
99 => array(), # c
100 => array(), # d
101 => array(), # e
102 => array(), # f
103 => array(), # g
104 => array(), # h
105 => array(), # i
106 => array(), # j
107 => array(), # k
108 => array(), # l
109 => array(), # m
110 => array(), # n
111 => array(), # o
112 => array(), # p
113 => array(), # q
114 => array(), # r
115 => array(), # s
116 => array(), # t
117 => array(), # u
118 => array(), # v
119 => array(), # w
120 => array(), # x
121 => array(), # y
122 => array(), # z
# 65 -> 90: Zie ascii tabel
123 => array(), # {
124 => array(), # |
125 => array(), # }
126 => array(), # ~
);
private $text = "** PHPHULP.NL **";
private $display = "display.jpg";
/**
* setText
* Stel de weer te geven tekst in
* @param String $text De tekst
*/
public function setText($text) {
$this->text = $text;
}
/**
* setDisplay
* Set het plaatje voor de achtergrond
* @param String $display De achtergrond
*/
public function setDisplay($display) {
$this->display = $display;
}
/**
* display
* Toon het display met de tekst
*/
public function display() {
header('content-type: image/jpeg');
$col = 0; // x-positie (0-15)
$line = 1.5; //y-positie (regel 0-3)
$img = imagecreatefromjpeg($this->display); // handle voor display image
// PLED-keuren
$blue = imagecolorallocate($img, 0,255,255);
$red = imagecolorallocate($img,255,64,64);
$green =imagecolorallocate($img,64,255,64);
$yellow =imagecolorallocate($img,255,255,64);
for ($e=0;$e<strlen($this->text);$e++){
$value = ord(substr($this->text,$e,1));
$char=$this->chars[$value];
$y=0;
foreach($char as $letter){
for ($bit=0;$bit<=strlen($letter);$bit++){
if (substr($letter,$bit,1)=="1"){
imagefilledrectangle ( $img,18+(($col*16)+(3*$bit)+1) ,20+ (($line*26)+(3*$y)+1), 19+(($col*16)+(3*$bit)+1) , 21+ (($line*26)+(3*$y)+1) ,$yellow ); // gele tekst
}
}
$y++;
}
$col++;
}
imagejpeg($img,"",100);
}
}
// Voorbeeld
$led = new PLED();
$led->setText("TEKST");
$led->display();
?>
/**
* PLED
* Met dit scriptje kun je een PLED- display simulatie nabootsen.
* Ik heb de standaard fontset toegevoegd (enkel hoofdletters).
* Kleine letter kun je gemakkelijk toevoegen. Zorg voor de juiste ascii waarde die je meegeeft in de keys.
* @author Tumbler
*/
class PLED {
private $chars = array(
# 32 -> 47: Zie ascii tabel
32 => array("00000","00000","00000","00000","00000","00000","00000","00000"), # space
33 => array("00100","00100","00100","00100","00100","00000","00100","00000"), # !
34 => array("01010","01010","01010","00000","00000","00000","00000","00000"), # "
35 => array("01010","01010","11111","01010","11111","01010","01010","00000"), # #
36 => array("00100","01111","10100","01110","00101","11110","00100","00000"), # $
37 => array("11000","11001","00010","00100","01000","10011","00011","00000"), # %
38 => array("01100","10010","10100","01000","10101","10010","01101","00000"), # &
39 => array("01100","00100","01000","00000","00000","00000","00000","00000"), # '
40 => array("00010","00100","01000","01000","01000","00100","00010","00000"), # (
41 => array("01000","00100","00010","00010","00010","00100","01000","00000"), # )
42 => array("00000","00100","10101","01110","10101","00100","00000","00000"), # *
43 => array("00000","00100","00100","11111","00100","00100","00000","00000"), # +
44 => array("00000","00000","00000","00000","01100","00100","01000","00000"), # ,
45 => array("00000","00000","00000","11111","00000","00000","00000","00000"), # -
46 => array("00000","00000","00000","00000","00000","01100","01100","00000"), # .
47 => array("00000","00001","00010","00100","01000","10000","00000","00000"), # /
# 48 -> 57: 0 - 9
48 => array("01110","10001","10011","10101","11001","10001","01110","00000"), # 0
49 => array("00100","01100","00100","00100","00100","00100","11111","00000"), # 1
50 => array("01110","10001","00001","00010","00100","01000","11111","00000"), # 2
51 => array("11111","00010","00100","00010","00001","10001","01110","00000"), # 3
52 => array("00010","00110","01010","10010","11111","00010","00010","00000"), # 4
53 => array("11111","10000","11110","00001","00001","10001","01110","00000"), # 5
54 => array("00110","01000","10000","11110","10001","10001","01110","00000"), # 6
55 => array("11111","00001","00010","00100","01000","01000","01000","00000"), # 7
56 => array("01110","10001","10001","01110","10001","10001","01110","00000"), # 8
57 => array("01110","10001","10001","01111","00001","00010","01100","00000"), # 9
# 58 -> 64: Zie ascii tabel
58 => array("00000","01100","01100","00000","01100","01100","00000","00000"), # :
59 => array("00000","01100","01100","00000","01100","00100","01000","00000"), # ;
60 => array("00010","00100","01000","10000","01000","00100","00010","00000"), # <
61 => array("00000","00000","11111","00000","11111","00000","00000","00000"), # =
62 => array("01000","00100","00010","00001","00010","00100","01000","00000"), # >
63 => array("01110","10001","00001","00010","00100","00000","00100","00000"), # ?
64 => array("01110","10001","00001","01101","10101","10101","01110","00000"), # @
# 65 -> 90: A - Z
65 => array("01110","10001","10001","11111","10001","10001","10001","00000"), # A
66 => array("11110","10001","10001","11110","10001","10001","11110","00000"), # B
67 => array("01110","10001","10000","10000","10000","10001","01110","00000"), # C
68 => array("11110","10001","10001","10001","10001","10001","11110","00000"), # D
69 => array("11111","10000","10000","11110","10000","10000","11111","00000"), # E
70 => array("11111","10000","10000","11110","10000","10000","10000","00000"), # F
71 => array("01110","10001","10000","10111","10001","10001","01111","00000"), # G
72 => array("10001","10001","10001","11111","10001","10001","10001","00000"), # H
73 => array("01110","00100","00100","00100","00100","00100","01110","00000"), # I
74 => array("00111","00010","00010","00010","00010","10010","01100","00000"), # J
75 => array("10001","10010","10100","11000","10100","10010","10001","00000"), # K
76 => array("10000","10000","10000","10000","10000","10000","11111","00000"), # L
77 => array("10001","11011","10101","10001","10001","10001","10001","00000"), # M
78 => array("10001","10001","11001","10101","10011","10001","10001","00000"), # N
79 => array("01110","10001","10001","10001","10001","10001","01110","00000"), # O
80 => array("11110","10001","10001","11110","10000","10000","10000","00000"), # P
81 => array("01110","10001","10001","10001","10101","10010","01101","00000"), # Q
82 => array("11110","10001","10001","11110","10100","10010","10001","00000"), # R
83 => array("01110","10001","10000","01110","00001","10001","01110","00000"), # S
84 => array("11111","00100","00100","00100","00100","00100","00100","00000"), # T
85 => array("10001","10001","10001","10001","10001","10001","01110","00000"), # U
86 => array("10001","10001","10001","10001","10001","01010","00100","00000"), # V
87 => array("10001","10001","10001","10001","10101","10101","01010","00000"), # W
88 => array("10001","10001","01010","00100","01010","10001","10001","00000"), # X
89 => array("10001","10001","01010","00100","00100","00100","00100","00000"), # Y
90 => array("11111","00001","00010","00100","01000","10000","11111","00000"), # Z
# 91 -> 98: Zie ascii tabel
91 => array("01110","01000","01000","01000","01000","01000","01110","00000"), # [
92 => array("10001","01010","11111","00100","11111","00100","00100","00000"), # \
93 => array("01110","00010","00010","00010","00010","00010","01110","00000"), # ]
94 => array("00100","01010","10001","00000","00000","00000","00000","00000"), # ^
95 => array("00000","00000","00000","00000","00000","00000","11111","00000"), # _
96 => array(), # `
# 65 -> 90: a - z
97 => array(), # a
98 => array(), # b
99 => array(), # c
100 => array(), # d
101 => array(), # e
102 => array(), # f
103 => array(), # g
104 => array(), # h
105 => array(), # i
106 => array(), # j
107 => array(), # k
108 => array(), # l
109 => array(), # m
110 => array(), # n
111 => array(), # o
112 => array(), # p
113 => array(), # q
114 => array(), # r
115 => array(), # s
116 => array(), # t
117 => array(), # u
118 => array(), # v
119 => array(), # w
120 => array(), # x
121 => array(), # y
122 => array(), # z
# 65 -> 90: Zie ascii tabel
123 => array(), # {
124 => array(), # |
125 => array(), # }
126 => array(), # ~
);
private $text = "** PHPHULP.NL **";
private $display = "display.jpg";
/**
* setText
* Stel de weer te geven tekst in
* @param String $text De tekst
*/
public function setText($text) {
$this->text = $text;
}
/**
* setDisplay
* Set het plaatje voor de achtergrond
* @param String $display De achtergrond
*/
public function setDisplay($display) {
$this->display = $display;
}
/**
* display
* Toon het display met de tekst
*/
public function display() {
header('content-type: image/jpeg');
$col = 0; // x-positie (0-15)
$line = 1.5; //y-positie (regel 0-3)
$img = imagecreatefromjpeg($this->display); // handle voor display image
// PLED-keuren
$blue = imagecolorallocate($img, 0,255,255);
$red = imagecolorallocate($img,255,64,64);
$green =imagecolorallocate($img,64,255,64);
$yellow =imagecolorallocate($img,255,255,64);
for ($e=0;$e<strlen($this->text);$e++){
$value = ord(substr($this->text,$e,1));
$char=$this->chars[$value];
$y=0;
foreach($char as $letter){
for ($bit=0;$bit<=strlen($letter);$bit++){
if (substr($letter,$bit,1)=="1"){
imagefilledrectangle ( $img,18+(($col*16)+(3*$bit)+1) ,20+ (($line*26)+(3*$y)+1), 19+(($col*16)+(3*$bit)+1) , 21+ (($line*26)+(3*$y)+1) ,$yellow ); // gele tekst
}
}
$y++;
}
$col++;
}
imagejpeg($img,"",100);
}
}
// Voorbeeld
$led = new PLED();
$led->setText("TEKST");
$led->display();
?>
Zie: http://www.asciitable.com/ voor een overzicht van de ASCI waardes (van alle tekens, inclusief de kleine letters) Misschien wel handig..
een overzicht van die tekens vind je hier : http://www.htvision.com/DOWNLOAD/HD44780.PDF (pag 18)
Elk karakter telt 5x8 dots. dus 8 rijen van 5 pixels. Eigenlijk is het maar 5x7 pixels, de laatste rij wordt gebruikt voor de cursor, maar kan eventueel ook meegenomen worden in de fontset.
Zoals Gerben eerder al aangaf :
124=> array("00000","00000","01010","10101","10001","01010","00100","00000")
Geef dus een hartje :)
00000
00000
01010
10101
01010
00100
00000
@Rik:
Vandaar dat ik maar enkel de hoofdletters toegevoegd heb. :)
Classe ziet er goed uit, zal m straks eens proberen.
Elk karakter telt 5x8 dots. dus 8 rijen van 5 pixels. Eigenlijk is het maar 5x7 pixels, de laatste rij wordt gebruikt voor de cursor, maar kan eventueel ook meegenomen worden in de fontset.
Zoals Gerben eerder al aangaf :
124=> array("00000","00000","01010","10101","10001","01010","00100","00000")
Geef dus een hartje :)
00000
00000
01010
10101
01010
00100
00000
@Rik:
Quote:
ah nu zie ik het. Dat is nogal wat werk, iemand anders daar zin in?
Vandaar dat ik maar enkel de hoofdletters toegevoegd heb. :)
Classe ziet er goed uit, zal m straks eens proberen.
Als je de $chars-array static maakt, hoeft PHP die niet bij iedere instantie van de klasse aan te maken maar deelt hij gewoon 1 setje arrays. Dat scheelt weer wat uitvoertijd en geheugen.
... al kan ik zo geen toepassing verzinnen van meerdere van deze dingen op 1 pagina. Wat je wel nog zou kunnen doen is naast de display-method ook nog een export-method aanmaken die het ding opslaat als een bestand. Dan verplaats je de teken-logica naar een protected method genaamd render of draw ofzo.
En misschien dat je de kleuren etc ook nog variabel kan maken. Die zijn nu hardcoded in de klasse.
... al kan ik zo geen toepassing verzinnen van meerdere van deze dingen op 1 pagina. Wat je wel nog zou kunnen doen is naast de display-method ook nog een export-method aanmaken die het ding opslaat als een bestand. Dan verplaats je de teken-logica naar een protected method genaamd render of draw ofzo.
En misschien dat je de kleuren etc ook nog variabel kan maken. Die zijn nu hardcoded in de klasse.
Voor Tommy: Dit is gewoon met een refresh. Met AJAX is het vast veel mooier.
Linkje.
Linkje.
Om te reageren heb je een account nodig en je moet ingelogd zijn.
Inhoudsopgave
Labels
- Geen tags toegevoegd.
PHP hulp
0 seconden vanaf nu