Skip to content

Commit

Permalink
Add the examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrocketfingers committed Aug 6, 2016
1 parent f206dc1 commit 1bdf6d0
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 0 deletions.
85 changes: 85 additions & 0 deletions examples/HelloWorld/HelloWorld.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* PCD8544 - Interface with Philips PCD8544 (or compatible) LCDs.
*
* Copyright (c) 2010 Carlos Rodrigues <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/*
* To use this sketch, connect the eight pins from your LCD like thus:
*
* Pin 1 -> +3.3V (rightmost, when facing the display head-on)
* Pin 2 -> Arduino digital pin 3
* Pin 3 -> Arduino digital pin 4
* Pin 4 -> Arduino digital pin 5
* Pin 5 -> Arduino digital pin 7
* Pin 6 -> Ground
* Pin 7 -> 10uF capacitor -> Ground
* Pin 8 -> Arduino digital pin 6
*
* Since these LCDs are +3.3V devices, you have to add extra components to
* connect it to the digital pins of the Arduino (not necessary if you are
* using a 3.3V variant of the Arduino, such as Sparkfun's Arduino Pro).
*/


#include <PCD8544.h>


// A custom glyph (a smiley)...
static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };


static PCD8544 lcd;


void setup() {
// PCD8544-compatible displays may have a different resolution...
lcd.begin(84, 48);

// Add the smiley to position "0" of the ASCII table...
lcd.createChar(0, glyph);
}


void loop() {
// Just to show the program is alive...
static int counter = 0;

// Write a piece of text on the first line...
lcd.setCursor(0, 0);
lcd.print("Hello, World!");

// Write the counter on the second line...
lcd.setCursor(0, 1);
lcd.print(counter, DEC);
lcd.write(' ');
lcd.write(0); // write the smiley

// Use a potentiometer to set the LCD contrast...
// short level = map(analogRead(A0), 0, 1023, 0, 127);
// lcd.setContrast(level);

delay(200);
counter++;
}


/* EOF - HelloWorld.ino */
104 changes: 104 additions & 0 deletions examples/Thermometer/Thermometer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Thermometer - read temperature using an LM35 sensor and display it on a PCD8544 LCD.
*
* Copyright (c) 2010 Carlos Rodrigues <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


#include <PCD8544.h>


static const byte sensorPin = 0;
static const byte ledPin = 13;

// The dimensions of the LCD (in pixels)...
static const byte LCD_WIDTH = 84;
static const byte LCD_HEIGHT = 48;

// The number of lines for the temperature chart...
static const byte CHART_HEIGHT = 5;

// A custom "degrees" symbol...
static const byte DEGREES_CHAR = 1;
static const byte degrees_glyph[] = { 0x00, 0x07, 0x05, 0x07, 0x00 };

// A bitmap graphic (10x2) of a thermometer...
static const byte THERMO_WIDTH = 10;
static const byte THERMO_HEIGHT = 2;
static const byte thermometer[] = { 0x00, 0x00, 0x48, 0xfe, 0x01, 0xfe, 0x00, 0x02, 0x05, 0x02,
0x00, 0x00, 0x62, 0xff, 0xfe, 0xff, 0x60, 0x00, 0x00, 0x00};

static PCD8544 lcd;


void setup() {
lcd.begin(LCD_WIDTH, LCD_HEIGHT);

// Register the custom symbol...
lcd.createChar(DEGREES_CHAR, degrees_glyph);

pinMode(ledPin, OUTPUT);

// The internal 1.1V reference provides for better
// resolution from the LM35, and is also more stable
// when powered from either a battery or USB...
analogReference(INTERNAL);
}


void loop() {
// Start beyond the edge of the screen...
static byte xChart = LCD_WIDTH;

digitalWrite(ledPin, HIGH);

// Read the temperature (in celsius)...
float temp = (1.1 * analogRead(sensorPin) * 100.0) / 1024.0;

// Print the temperature (using the custom "degrees" symbol)...
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp, 1);
lcd.print(" \001C ");

// Draw the thermometer bitmap at the bottom left corner...
lcd.setCursor(0, LCD_HEIGHT/8 - THERMO_HEIGHT);
lcd.drawBitmap(thermometer, THERMO_WIDTH, THERMO_HEIGHT);

// Wrap the chart's current position...
if (xChart >= LCD_WIDTH) {
xChart = THERMO_WIDTH + 2;
}

// Update the temperature chart...
lcd.setCursor(xChart, 1);
lcd.drawColumn(CHART_HEIGHT, map(temp, 0, 45, 0, CHART_HEIGHT*8)); // ...clipped to the 0-45C range.
lcd.drawColumn(CHART_HEIGHT, 0); // ...with a clear marker to see the current chart position.

xChart++;

digitalWrite(ledPin, LOW);
delay(500);
}


/* EOF - Thermometer.ino */

0 comments on commit 1bdf6d0

Please sign in to comment.