Added auxillery files that are not needed
This commit is contained in:
parent
8e78b2eb01
commit
fc8eb0773a
|
@ -1,247 +0,0 @@
|
|||
/*
|
||||
ChronoLCD Color - An example sketch for the Color LCD Shield Library
|
||||
by: Jim Lindblom
|
||||
SparkFun Electronics
|
||||
date: 6/23/11
|
||||
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
||||
use this code however you'd like, just keep this license and
|
||||
attribute. Let me know if you make hugely, awesome, great changes.
|
||||
|
||||
This sketch draws an analog and digital clock on the Color LCD
|
||||
Shield. You can also use the on-board buttons to set the hours
|
||||
and minutes.
|
||||
|
||||
Use the defines at the top of the code to set the initial time.
|
||||
You can also adjust the size and color of the clock.
|
||||
|
||||
To set the time, first hit S3. Then use S1 and S2 to adjust the
|
||||
hours and minutes respsectively. Hit S3 to start the clock
|
||||
back up.
|
||||
|
||||
This example code should give you a good idea of how to use
|
||||
the setCircle, setLine, and setStr functions of the Color LCD
|
||||
Shield Library.
|
||||
*/
|
||||
#include <ColorLCDShield.h>
|
||||
|
||||
// Enter the time below in 12-hr format
|
||||
#define HOURS 10
|
||||
#define MINUTES 21
|
||||
#define SECONDS 00
|
||||
#define AMPM 0 // enter 0 for AM, 1 for PM
|
||||
|
||||
#define CLOCK_RADIUS 45 // radius of clock face
|
||||
#define CLOCK_CENTER 50 // If you adjust the radius, you'll probably want to adjust this
|
||||
#define H_LENGTH 25 // length of hour hand
|
||||
#define M_LENGTH 35 // length of minute hand
|
||||
#define S_LENGTH 43 // length of second hand
|
||||
|
||||
#define BACKGROUND BLACK // room for growth, adjust the background color according to daylight
|
||||
#define C_COLOR RED // This is the color of the clock face, and digital clock
|
||||
#define H_COLOR BLUE // hour hand color
|
||||
#define M_COLOR GREEN // minute hand color
|
||||
#define S_COLOR YELLOW // second hand color
|
||||
|
||||
LCDShield lcd;
|
||||
|
||||
int hours, minutes, seconds, ampm;
|
||||
int buttonPins[3] = {3, 4, 5};
|
||||
|
||||
void setup()
|
||||
{
|
||||
/* Set up the button pins as inputs, set pull-up resistor */
|
||||
for (int i=0; i<3; i++)
|
||||
{
|
||||
pinMode(buttonPins[i], INPUT);
|
||||
digitalWrite(buttonPins[i], HIGH);
|
||||
}
|
||||
|
||||
hours = HOURS;
|
||||
minutes = MINUTES;
|
||||
seconds = SECONDS;
|
||||
ampm = AMPM;
|
||||
|
||||
/* Initialize the LCD, set the contrast, clear the screen */
|
||||
lcd.init(PHILIPS);
|
||||
lcd.contrast(-63);
|
||||
lcd.clear(BACKGROUND);
|
||||
|
||||
drawClock(); // Draw the clock face, this includes 12, 3, 6, 9
|
||||
displayAnalogTime(hours, minutes, seconds); // Draw the clock hands
|
||||
displayDigitalTime(hours, minutes, seconds, ampm); // Draw the digital clock text
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
/* We'll run around checking for button presses,
|
||||
until it's been a second */
|
||||
while(millis() % 1000)
|
||||
{
|
||||
if (!digitalRead(buttonPins[2]))
|
||||
setTime(); // If S3 was pressed, go set the time
|
||||
}
|
||||
|
||||
/* We'll get here if it's been a second. We need to increase
|
||||
seconds by 1 and then go from there */
|
||||
seconds++;
|
||||
if (seconds >= 60)
|
||||
{
|
||||
seconds = 0; // If seconds is 60, set it back to 0
|
||||
minutes++; // and increase minutes by 1
|
||||
if (minutes >= 60)
|
||||
{
|
||||
minutes = 0; // If minutes is 60, set it back to 0
|
||||
hours++; // and increase hours by 1
|
||||
if (hours == 12)
|
||||
ampm ^= 1; // If it's 12 o'clock, flip ampm
|
||||
if (hours >= 13)
|
||||
hours = 1; // If hours is 13, set it to 1. 12-hr clock.
|
||||
}
|
||||
}
|
||||
/* Once each second, we'll redraw the clock with new values */
|
||||
drawClock();
|
||||
displayAnalogTime(hours, minutes, seconds);
|
||||
displayDigitalTime(hours, minutes, seconds, ampm);
|
||||
}
|
||||
/*
|
||||
setTime uses on-shield switches S1, S2, and S3 to set the time
|
||||
pressing S3 will exit the function. S1 increases hours, S2
|
||||
increases seconds.
|
||||
*/
|
||||
void setTime()
|
||||
{
|
||||
/* Reset the clock to midnight */
|
||||
seconds = 0;
|
||||
minutes = 0;
|
||||
hours = 12;
|
||||
ampm = 0;
|
||||
|
||||
/* Draw the clock, so we can see the new time */
|
||||
drawClock();
|
||||
displayAnalogTime(hours, minutes, seconds);
|
||||
displayDigitalTime(hours, minutes, seconds, ampm);
|
||||
|
||||
while (!digitalRead(buttonPins[2]))
|
||||
; // wait till they let go of S1
|
||||
|
||||
/* We'll run around this loop until S3 is pressed again */
|
||||
while(digitalRead(buttonPins[2]))
|
||||
{
|
||||
/* If S1 is pressed, we'll update the hours */
|
||||
if (!digitalRead(buttonPins[0]))
|
||||
{
|
||||
hours++; // Increase hours by 1
|
||||
if (hours == 12)
|
||||
ampm ^= 1; // Flip am/pm if it's 12 o'clock
|
||||
if (hours >= 13)
|
||||
hours = 1; // Set hours to 1 if it's 13. 12-hour clock.
|
||||
|
||||
/* and update the clock, so we can see it */
|
||||
drawClock();
|
||||
displayAnalogTime(hours, minutes, seconds);
|
||||
displayDigitalTime(hours, minutes, seconds, ampm);
|
||||
}
|
||||
if (!digitalRead(buttonPins[1]))
|
||||
{
|
||||
minutes++; // Increase minutes by 1
|
||||
if (minutes >= 60)
|
||||
minutes = 0; // If minutes is 60, set it back to 0
|
||||
|
||||
/* and update the clock, so we can see it */
|
||||
drawClock();
|
||||
displayAnalogTime(hours, minutes, seconds);
|
||||
displayDigitalTime(hours, minutes, seconds, ampm);
|
||||
}
|
||||
}
|
||||
/* Once S3 is pressed, we'll exit, but not until it's released */
|
||||
while(!digitalRead(buttonPins[2]))
|
||||
;
|
||||
}
|
||||
|
||||
/*
|
||||
displayDigitalTime() takes in values for hours, minutes, seconds
|
||||
and am/pm. It'll print the time, in digital format, on the
|
||||
bottom of the screen.
|
||||
*/
|
||||
void displayDigitalTime(int h, int m, int s, int ap)
|
||||
{
|
||||
char timeChar[12];
|
||||
|
||||
if (!ap)
|
||||
{
|
||||
sprintf(timeChar, "%.2d:%.2d:%.2d AM", h, m, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(timeChar, "%.2d:%.2d:%.2d PM", h, m, s);
|
||||
}
|
||||
/* Print the time on the clock */
|
||||
lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 4, 22,
|
||||
C_COLOR, BACKGROUND);
|
||||
}
|
||||
|
||||
/*
|
||||
drawClock() simply draws the outer circle of the clock, and '12',
|
||||
'3', '6', and '9'. Room for growth here, if you want to customize
|
||||
your clock. Maybe add dashe marks, or even all 12 digits.
|
||||
*/
|
||||
void drawClock()
|
||||
{
|
||||
/* Draw the circle */
|
||||
lcd.setCircle(CLOCK_CENTER, 66, CLOCK_RADIUS, C_COLOR);
|
||||
|
||||
/* Print 12, 3, 6, 9, a lot of arbitrary values are used here
|
||||
for the coordinates. Just used trial and error to get them
|
||||
into a nice position. */
|
||||
lcd.setStr("12", CLOCK_CENTER - CLOCK_RADIUS, 66-9, C_COLOR, BACKGROUND);
|
||||
lcd.setStr("3", CLOCK_CENTER - 9, 66 + CLOCK_RADIUS - 12, C_COLOR, BACKGROUND);
|
||||
lcd.setStr("6", CLOCK_CENTER + CLOCK_RADIUS - 18, 66-4, C_COLOR, BACKGROUND);
|
||||
lcd.setStr("9", CLOCK_CENTER - 9, 66 - CLOCK_RADIUS + 4, C_COLOR, BACKGROUND);
|
||||
}
|
||||
|
||||
/*
|
||||
displayAnalogTime() draws the three clock hands in their proper
|
||||
position. Room for growth here, I'd like to make the clock hands
|
||||
arrow shaped, or at least thicker and more visible.
|
||||
*/
|
||||
void displayAnalogTime(int h, int m, int s)
|
||||
{
|
||||
double midHours; // this will be used to slightly adjust the hour hand
|
||||
static int hx, hy, mx, my, sx, sy;
|
||||
|
||||
/* Adjust time to shift display 90 degrees ccw
|
||||
this will turn the clock the same direction as text */
|
||||
h -= 3;
|
||||
m -= 15;
|
||||
s -= 15;
|
||||
if (h <= 0)
|
||||
h += 12;
|
||||
if (m < 0)
|
||||
m += 60;
|
||||
if (s < 0)
|
||||
s += 60;
|
||||
|
||||
/* Delete old lines: */
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, BACKGROUND); // delete second hand
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, BACKGROUND); // delete minute hand
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, BACKGROUND); // delete hour hand
|
||||
|
||||
/* Calculate and draw new lines: */
|
||||
s = map(s, 0, 60, 0, 360); // map the 0-60, to "360 degrees"
|
||||
sx = S_LENGTH * sin(3.14 * ((double) s)/180); // woo trig!
|
||||
sy = S_LENGTH * cos(3.14 * ((double) s)/180); // woo trig!
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, S_COLOR); // print second hand
|
||||
|
||||
m = map(m, 0, 60, 0, 360); // map the 0-60, to "360 degrees"
|
||||
mx = M_LENGTH * sin(3.14 * ((double) m)/180); // woo trig!
|
||||
my = M_LENGTH * cos(3.14 * ((double) m)/180); // woo trig!
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, M_COLOR); // print minute hand
|
||||
|
||||
midHours = minutes/12; // midHours is used to set the hours hand to middling levels between whole hours
|
||||
h *= 5; // Get hours and midhours to the same scale
|
||||
h += midHours; // add hours and midhours
|
||||
h = map(h, 0, 60, 0, 360); // map the 0-60, to "360 degrees"
|
||||
hx = H_LENGTH * sin(3.14 * ((double) h)/180); // woo trig!
|
||||
hy = H_LENGTH * cos(3.14 * ((double) h)/180); // woo trig!
|
||||
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, H_COLOR); // print hour hand
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
// This Sample Created by Tony Contrada (2/22/2013) for use with the Sparkfun Color LCD Shield
|
||||
// with the updated Arduino Color LCD Library.
|
||||
// This sample sketch illustrates the new setArf method and an updated setCircle method
|
||||
// which includes setting a Line Thickness in Pixels and the ability to Fill-In the circle.
|
||||
|
||||
#include <ColorLCDShield.h>
|
||||
|
||||
LCDShield lcd; // Creates an LCDShield, named lcd
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.init(PHILIPS); // Initializes lcd, using an PHILIPSdriver
|
||||
lcd.contrast(-64); // -51's usually a good contrast value
|
||||
lcd.clear(BLACK); // clear the screen
|
||||
|
||||
//Creates RED Arc in the ENE Quadrant with a Line Thickness of 5 Pixels
|
||||
int segmentsRed[1] = {ENE};
|
||||
lcd.setArc(60,50,40,segmentsRed,sizeof(segmentsRed),5,RED);
|
||||
|
||||
//Creates YELLOW Arc in the NNE Quadrant with a Line Thickness of 10 Pixels
|
||||
int segmentsYellow[1] = {NNE};
|
||||
lcd.setArc(60,50,40,segmentsYellow,sizeof(segmentsYellow),10,YELLOW);
|
||||
|
||||
//Creates GREEN Arc in the WNW and NNW Quadrants with a FILL
|
||||
int segments[2] = {WNW,NNW};
|
||||
lcd.setArc(60,50,40,segments,sizeof(segments),FILL,GREEN);
|
||||
|
||||
//Creates PINK Circle with a FILL
|
||||
lcd.setCircle(90,100,20,PINK,FILL);
|
||||
|
||||
//Creates CYAN Circle with a Line Thickness of 3 Pixels
|
||||
lcd.setCircle(90,35,25,CYAN,3);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
TestPattern - An example sketch for the Color LCD Shield Library
|
||||
by: Jim Lindblom
|
||||
SparkFun Electronics
|
||||
date: 6/23/11
|
||||
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
||||
use this code however you'd like, just keep this license and
|
||||
attribute. Let me know if you make hugely, awesome, great changes.
|
||||
|
||||
This sketch has example usage of the Color LCD Shield's three
|
||||
buttons. It also shows how to use the setRect and contrast
|
||||
functions.
|
||||
|
||||
Hit S1 to increase the contrast, S2 decreases the contrast, and
|
||||
S3 sets the contrast back to the middle.
|
||||
*/
|
||||
#include <ColorLCDShield.h>
|
||||
|
||||
LCDShield lcd;
|
||||
|
||||
int buttons[3] = {3, 4, 5}; // S1 = 3, S2 = 4, S3 = 5
|
||||
signed char cont = -51; // Philips medium contrast
|
||||
//signed char cont = 40; // Epson medium contrast
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
for (int i=0; i<3; i++)
|
||||
{
|
||||
pinMode(buttons[i], INPUT); // Set buttons as inputs
|
||||
digitalWrite(buttons[i], HIGH); // Activate internal pull-up
|
||||
}
|
||||
|
||||
// Initialize the LCD, try using EPSON if it's not working
|
||||
lcd.init(PHILIPS);
|
||||
// lcd.init(PHILIPS, 1); // Philips init with colors swapped. (Try this if red makes blue, etc).
|
||||
lcd.contrast(cont); // Initialize contrast
|
||||
lcd.clear(WHITE); // Set background to white
|
||||
lcd.printLogo(); // Print SparkFun test logo
|
||||
testPattern(); // Print color bars on bottom of screen
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while(digitalRead(buttons[0])&&digitalRead(buttons[1])&&digitalRead(buttons[2]))
|
||||
; // Wait, do nothing, until a button is pressed
|
||||
if (!digitalRead(buttons[0])) // If S1 is hit, increase contrast
|
||||
{
|
||||
cont++;
|
||||
if (cont > 63) // Philips contrast goes from 63 to -64
|
||||
cont = -64;
|
||||
}
|
||||
else if (!digitalRead(buttons[1])) // If s2 is hit, decrease contrast
|
||||
{
|
||||
cont--;
|
||||
if (cont < -64)
|
||||
cont = 63;
|
||||
}
|
||||
else if (!digitalRead(buttons[2])) // If S3 is hit, reset contrast
|
||||
{
|
||||
cont = 0;
|
||||
}
|
||||
lcd.contrast(cont); // give LCD contrast command
|
||||
Serial.println(cont);
|
||||
|
||||
delay(100); // Delay to give each button press a little more meaning
|
||||
}
|
||||
|
||||
void testPattern()
|
||||
{
|
||||
lcd.setRect(80, 2, 131, 19, 1, WHITE);
|
||||
lcd.setRect(80, 19, 131, 35, 1, YELLOW);
|
||||
lcd.setRect(80, 35, 131, 51, 1, CYAN);
|
||||
lcd.setRect(80, 51, 131, 67, 1, GREEN);
|
||||
lcd.setRect(80, 67, 131, 83, 1, MAGENTA);
|
||||
lcd.setRect(80, 83, 131, 99, 1, RED);
|
||||
lcd.setRect(80, 99, 131, 115, 1, BLUE);
|
||||
lcd.setRect(80, 115, 131, 131, 1, BLACK);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
ZanyCircles - An example sketch for the Color LCD Shield Library
|
||||
by: Jim Lindblom
|
||||
SparkFun Electronics
|
||||
date: 6/23/11
|
||||
license: CC-BY SA 3.0 - Creative commons share-alike 3.0
|
||||
use this code however you'd like, just keep this license and
|
||||
attribute. Let me know if you make hugely, awesome, great changes.
|
||||
|
||||
This simple sketch shows how you can use setCircle and setPixel
|
||||
with the Color LCD Shield library.
|
||||
*/
|
||||
#include <ColorLCDShield.h>
|
||||
|
||||
#define CIRCLES 10 // Number of zany circles in display
|
||||
#define BACKGROUND ORANGE // Color of background
|
||||
#define FOREGROUND BLUE // color of circles
|
||||
|
||||
int radius = 1; // size of circles
|
||||
int jump = 5; // +/- of possible jump
|
||||
int xCir[CIRCLES]; // center points of circles
|
||||
int yCir[CIRCLES]; // cetner points of circles
|
||||
|
||||
LCDShield lcd;
|
||||
|
||||
void setup()
|
||||
{
|
||||
lcd.init(PHILIPS); // Try EPSON if this doesn't work. If colors are swapped try init(PHILIPS, 1)
|
||||
lcd.contrast(-51); // Feel free to change this for visibility, values between 0 and 60
|
||||
lcd.clear(BACKGROUND);
|
||||
|
||||
// Initilize all circles' center points
|
||||
for (int i=0; i<CIRCLES; i++)
|
||||
{
|
||||
//xCir[i] = random(2, 131); // random starting points
|
||||
//yCir[i] = random(2, 131);
|
||||
xCir[i] = 66; // start in the middle
|
||||
yCir[i] = 66;
|
||||
|
||||
// Circles must be stuck inside the box:
|
||||
if (xCir[i] >= 131-radius)
|
||||
xCir[i] = 131-radius;
|
||||
if (xCir[i] <= radius)
|
||||
xCir[i] = radius;
|
||||
if (yCir[i] >= 131-radius)
|
||||
yCir[i] = 131-radius;
|
||||
if (yCir[i] <= radius)
|
||||
yCir[i] = radius;
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (int i=0; i<CIRCLES; i++)
|
||||
{
|
||||
// add a random number to x, y
|
||||
xCir[i] += random(-jump, jump+1);
|
||||
yCir[i] += random(-jump, jump+1);
|
||||
|
||||
// Circles must be stuck inside the box:
|
||||
if (xCir[i] >= 131-radius)
|
||||
xCir[i] = 131-radius;
|
||||
if (xCir[i] <= radius)
|
||||
xCir[i] = radius;
|
||||
if (yCir[i] >= 131-radius)
|
||||
yCir[i] = 131-radius;
|
||||
if (yCir[i] <= radius)
|
||||
yCir[i] = radius;
|
||||
}
|
||||
for (int i=0; i<CIRCLES; i++)
|
||||
{
|
||||
for (int j=1; j<=radius; j++)
|
||||
{
|
||||
lcd.setCircle(xCir[i], yCir[i], j, FOREGROUND); // draw the new circle
|
||||
lcd.setPixel(FOREGROUND, xCir[i], yCir[i]); // fill in the center of the new circle
|
||||
}
|
||||
}
|
||||
delay(50); // Little delay for visibility
|
||||
for (int i=0; i<CIRCLES; i++)
|
||||
{
|
||||
for (int j=1; j<=radius; j++)
|
||||
{
|
||||
lcd.setCircle(xCir[i], yCir[i], j, BACKGROUND); // clear the circle
|
||||
lcd.setPixel(BACKGROUND, xCir[i], yCir[i]); // clear center of circle
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue