Project

General

Profile

Statistics
| Branch: | Revision:

root / arduino-1.0 / libraries / LiquidCrystal / examples / CustomCharacter / CustomCharacter.ino @ 58d82c77

History | View | Annotate | Download (2.64 KB)

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
 created21 Mar 2011
26
 by Tom Igoe
27
 Based on Adafruit's example at
28
 https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
29
 
30
 This example code is in the public domain.
31
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
32
 
33
 Also useful:
34
 http://icontexto.com/charactercreator/
35
 
36
 */
37

    
38
// include the library code:
39
#include <LiquidCrystal.h>
40

    
41
// initialize the library with the numbers of the interface pins
42
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
43

    
44
// make some custom characters:
45
byte heart[8] = {
46
  0b00000,
47
  0b01010,
48
  0b11111,
49
  0b11111,
50
  0b11111,
51
  0b01110,
52
  0b00100,
53
  0b00000
54
};
55

    
56
byte smiley[8] = {
57
  0b00000,
58
  0b00000,
59
  0b01010,
60
  0b00000,
61
  0b00000,
62
  0b10001,
63
  0b01110,
64
  0b00000
65
};
66

    
67
byte frownie[8] = {
68
  0b00000,
69
  0b00000,
70
  0b01010,
71
  0b00000,
72
  0b00000,
73
  0b00000,
74
  0b01110,
75
  0b10001
76
};
77

    
78
byte armsDown[8] = {
79
  0b00100,
80
  0b01010,
81
  0b00100,
82
  0b00100,
83
  0b01110,
84
  0b10101,
85
  0b00100,
86
  0b01010
87
};
88

    
89
byte armsUp[8] = {
90
  0b00100,
91
  0b01010,
92
  0b00100,
93
  0b10101,
94
  0b01110,
95
  0b00100,
96
  0b00100,
97
  0b01010
98
};
99
void setup() {
100
  // create a new character
101
  lcd.createChar(0, heart);
102
  // create a new character
103
  lcd.createChar(1, smiley);
104
  // create a new character
105
  lcd.createChar(2, frownie);
106
  // create a new character
107
  lcd.createChar(3, armsDown);  
108
  // create a new character
109
  lcd.createChar(4, armsUp);  
110

    
111
  // set up the lcd's number of columns and rows: 
112
  lcd.begin(16, 2);
113
  // Print a message to the lcd.
114
  lcd.print("I "); 
115
  lcd.write(0);
116
  lcd.print(" Arduino! ");
117
  lcd.write(1);
118

    
119
}
120

    
121
void loop() {
122
  // read the potentiometer on A0:
123
  int sensorReading = analogRead(A0);
124
  // map the result to 200 - 1000:
125
  int delayTime = map(sensorReading, 0, 1023, 200, 1000);
126
  // set the cursor to the bottom row, 5th position:
127
  lcd.setCursor(4, 1);
128
  // draw the little man, arms down:
129
  lcd.write(3);
130
  delay(delayTime);
131
  lcd.setCursor(4, 1);
132
  // draw him arms up:
133
  lcd.write(4);
134
  delay(delayTime); 
135
}
136

    
137

    
138