117 lines
2.1 KiB
Arduino
117 lines
2.1 KiB
Arduino
|
/*
|
||
|
LiquidCrystal Library - Custom Characters The circuit:
|
||
|
* LCD RS pin to digital pin 12
|
||
|
* LCD Enable pin to digital pin 11
|
||
|
* LCD D4 pin to digital pin 5
|
||
|
* LCD D5 pin to digital pin 4
|
||
|
* LCD D6 pin to digital pin 3
|
||
|
* LCD D7 pin to digital pin 2
|
||
|
* LCD R/W pin to ground
|
||
|
* 10K potentiometer:
|
||
|
* ends to +5V and ground
|
||
|
* wiper to LCD VO pin (pin 3)
|
||
|
* 10K poterntiometer on pin A0
|
||
|
|
||
|
https://mikeyancey.com/hamcalc/lcd_characters.php
|
||
|
*/
|
||
|
// include the library code:
|
||
|
#include <LiquidCrystal.h>
|
||
|
|
||
|
// initialize the library with the numbers of the interface pins
|
||
|
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);
|
||
|
|
||
|
// make some custom characters:
|
||
|
byte heart[8] = {
|
||
|
0b00000,
|
||
|
0b01010,
|
||
|
0b11111,
|
||
|
0b11111,
|
||
|
0b11111,
|
||
|
0b01110,
|
||
|
0b00100,
|
||
|
0b00000
|
||
|
};
|
||
|
|
||
|
byte smiley[8] = {
|
||
|
0b00000,
|
||
|
0b00000,
|
||
|
0b01010,
|
||
|
0b00000,
|
||
|
0b00000,
|
||
|
0b10001,
|
||
|
0b01110,
|
||
|
0b00000
|
||
|
};
|
||
|
|
||
|
byte frownie[8] = {
|
||
|
0b00000,
|
||
|
0b00000,
|
||
|
0b01010,
|
||
|
0b00000,
|
||
|
0b00000,
|
||
|
0b00000,
|
||
|
0b01110,
|
||
|
0b10001
|
||
|
};
|
||
|
|
||
|
byte armsDown[8] = {
|
||
|
0b00100,
|
||
|
0b01010,
|
||
|
0b00100,
|
||
|
0b00100,
|
||
|
0b01110,
|
||
|
0b10101,
|
||
|
0b00100,
|
||
|
0b01010
|
||
|
};
|
||
|
|
||
|
byte armsUp[8] = {
|
||
|
0b00100,
|
||
|
0b01010,
|
||
|
0b00100,
|
||
|
0b10101,
|
||
|
0b01110,
|
||
|
0b00100,
|
||
|
0b00100,
|
||
|
0b01010
|
||
|
};
|
||
|
|
||
|
void setup() {
|
||
|
// initialize LCD and set up the number of columns and rows:
|
||
|
lcd.begin(16, 2);
|
||
|
|
||
|
// create a new character
|
||
|
lcd.createChar(0, heart);
|
||
|
// create a new character
|
||
|
lcd.createChar(1, smiley);
|
||
|
// create a new character
|
||
|
lcd.createChar(2, frownie);
|
||
|
// create a new character
|
||
|
lcd.createChar(3, armsDown);
|
||
|
// create a new character
|
||
|
lcd.createChar(4, armsUp);
|
||
|
lcd.setCursor(0, 0);
|
||
|
// Print a message to the lcd.
|
||
|
lcd.print("I ");
|
||
|
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
|
||
|
lcd.print(" Arduino! ");
|
||
|
lcd.write((byte) 1);
|
||
|
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
// read the potentiometer on A0:
|
||
|
int sensorReading = analogRead(A0);
|
||
|
// map the result to 200 - 1000:
|
||
|
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
|
||
|
// set the cursor to the bottom row, 5th position:
|
||
|
lcd.setCursor(4, 1);
|
||
|
// draw the little man, arms down:
|
||
|
lcd.write(3);
|
||
|
delay(delayTime);
|
||
|
lcd.setCursor(4, 1);
|
||
|
// draw him arms up:
|
||
|
lcd.write(4);
|
||
|
delay(delayTime);
|
||
|
}
|