source: rtos_arduino/trunk/arduino_lib/libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 2.8 KB
Line 
1/*
2 LiquidCrystal Library - Custom Characters
3
4 Demonstrates how to add custom characters on an LCD display.
5 The LiquidCrystal library works with all LCD displays that are
6 compatible with the Hitachi HD44780 driver. There are many of
7 them out there, and you can usually tell them by the 16-pin interface.
8
9 This sketch prints "I <heart> Arduino!" and a little dancing man
10 to the LCD.
11
12 The circuit:
13 * LCD RS pin to digital pin 12
14 * LCD Enable pin to digital pin 11
15 * LCD D4 pin to digital pin 5
16 * LCD D5 pin to digital pin 4
17 * LCD D6 pin to digital pin 3
18 * LCD D7 pin to digital pin 2
19 * LCD R/W pin to ground
20 * 10K potentiometer:
21 * ends to +5V and ground
22 * wiper to LCD VO pin (pin 3)
23 * 10K poterntiometer on pin A0
24
25 created 21 Mar 2011
26 by Tom Igoe
27 modified 11 Nov 2013
28 by Scott Fitzgerald
29
30 Based on Adafruit's example at
31 https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
32
33 This example code is in the public domain.
34 http://www.arduino.cc/en/Tutorial/LiquidCrystal
35
36 Also useful:
37 http://icontexto.com/charactercreator/
38
39 */
40
41// include the library code:
42#include <LiquidCrystal.h>
43
44// initialize the library with the numbers of the interface pins
45LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
46
47// make some custom characters:
48byte heart[8] = {
49 0b00000,
50 0b01010,
51 0b11111,
52 0b11111,
53 0b11111,
54 0b01110,
55 0b00100,
56 0b00000
57};
58
59byte smiley[8] = {
60 0b00000,
61 0b00000,
62 0b01010,
63 0b00000,
64 0b00000,
65 0b10001,
66 0b01110,
67 0b00000
68};
69
70byte frownie[8] = {
71 0b00000,
72 0b00000,
73 0b01010,
74 0b00000,
75 0b00000,
76 0b00000,
77 0b01110,
78 0b10001
79};
80
81byte armsDown[8] = {
82 0b00100,
83 0b01010,
84 0b00100,
85 0b00100,
86 0b01110,
87 0b10101,
88 0b00100,
89 0b01010
90};
91
92byte armsUp[8] = {
93 0b00100,
94 0b01010,
95 0b00100,
96 0b10101,
97 0b01110,
98 0b00100,
99 0b00100,
100 0b01010
101};
102
103void setup() {
104 // initialize LCD and set up the number of columns and rows:
105 lcd.begin(16, 2);
106
107 // create a new character
108 lcd.createChar(0, heart);
109 // create a new character
110 lcd.createChar(1, smiley);
111 // create a new character
112 lcd.createChar(2, frownie);
113 // create a new character
114 lcd.createChar(3, armsDown);
115 // create a new character
116 lcd.createChar(4, armsUp);
117
118 // Print a message to the lcd.
119 lcd.print("I ");
120 lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
121 lcd.print(" Arduino! ");
122 lcd.write((byte) 1);
123
124}
125
126void loop() {
127 // read the potentiometer on A0:
128 int sensorReading = analogRead(A0);
129 // map the result to 200 - 1000:
130 int delayTime = map(sensorReading, 0, 1023, 200, 1000);
131 // set the cursor to the bottom row, 5th position:
132 lcd.setCursor(4, 1);
133 // draw the little man, arms down:
134 lcd.write(3);
135 delay(delayTime);
136 lcd.setCursor(4, 1);
137 // draw him arms up:
138 lcd.write(4);
139 delay(delayTime);
140}
Note: See TracBrowser for help on using the repository browser.