Upload
denydi
View
231
Download
1
Embed Size (px)
Citation preview
8/18/2019 Arduino Projects Experiments Part7
1/20
8/18/2019 Arduino Projects Experiments Part7
2/20
8/18/2019 Arduino Projects Experiments Part7
3/20
Figure 14-5. The LCD News Reader Fritzing diagram
Example 14-1. The LCD News Reader sketch
/*
The LCD News Reader
20 August 2013
*/
// include the LCD library code:
#include
// set up pins on Arduino for LCD and test lead
LiquidCrystal lcd(12,11,5,4,3,2);
// set up the LCD's number of columns and rows
#define Xdelay 1900
String a;
String b;
String c;
String d;
Chapter 14: The LCD News Reader 123
8/18/2019 Arduino Projects Experiments Part7
4/20
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
clearLCD();
backlightOn();
lcd.print("HELLO, WORLD!");
delay(Xdelay);
}
void loop()
{
char databuff[16];
char dispbuff[16];
// display on/off test
for(int x = 5; x>0; x--)
{
delay(1000);
displayOff();
delay(1000);
displayOn();
}
clearLCD();
backlightOn();
lcd.print("SLOW FADE ");
fadeOut(100);
fadeIn(10);
// light up all segments as a test
lcd.print("0123456789abcdef");
delay(Xdelay);
lcd.print("ghijklmnopqrstuv");
delay(Xdelay);
lcd.print("wxyz +?*&%$#()!=");
delay(Xdelay);
lcd.print(" ");
delay(Xdelay);
lcd.print(" "); delay(Xdelay);
a = "0123456789abcdef";
b = "ghijklmnopqrstuv";
c = "wxyz +?*&%$#()!=";
d = " ";
124 Make: Basic Arduino Projects
8/18/2019 Arduino Projects Experiments Part7
5/20
selectLineTwo();
lcd.print(a);
delay(Xdelay);
selectLineOne();
lcd.print(a);
selectLineTwo();
lcd.print(b);
delay(Xdelay);
selectLineOne();
lcd.print(b);
selectLineTwo();
lcd.print(c);
delay(Xdelay);
selectLineOne();
lcd.print(c);
selectLineTwo();
lcd.print(d);
delay(Xdelay);
selectLineOne();
lcd.print(d);
selectLineTwo();
lcd.print(d);
delay(Xdelay);
for (int x = 0; x=0; i--)
{
goTo(i);
if (i%4 == 1)
lcd.print("- ");
if (i%4 == 2)
lcd.print("I ");
if (i%4 == 3)
lcd.print("- ");
if (i%4 == 0)
lcd.print("I ");
delay(100);
}
for(int i =0; i
8/18/2019 Arduino Projects Experiments Part7
6/20
void selectLineOne()
{
lcd.write(0xFE); //command flag
lcd.write(128); //position
delay(10);
}
void selectLineTwo()
{
lcd.write(0xFE); //command flag
lcd.write(192); //position
delay(10);
}
void goTo(int position)
{
if (position
8/18/2019 Arduino Projects Experiments Part7
7/20
}
void displayOn()
{
lcd.write(0xFE); //command flag
lcd.write(0x0C); //clear command
delay(10);
}
void displayOff()
{
lcd.write(0xFE); //command flag
lcd.write(0x08); //clear command
delay(10);
}
void fadeOut(int fade)
{
for (int x = 157; x>128; x--)
{
backlightValue(x);
delay(fade);
}
}
void fadeIn(int fade)
{
for (int x = 128; x
8/18/2019 Arduino Projects Experiments Part7
8/20
8/18/2019 Arduino Projects Experiments Part7
9/20
Figure 14-7. The LCD News Reader block diagram
Figure 14-8. The LCD News Reader circuit schematic diagram
Something to Think AboutHow can a pushbutton switch be used to control the display?
Chapter 14: The LCD News Reader 129
8/18/2019 Arduino Projects Experiments Part7
10/20
8/18/2019 Arduino Projects Experiments Part7
11/20
8/18/2019 Arduino Projects Experiments Part7
12/20
8/18/2019 Arduino Projects Experiments Part7
13/20
Figure 15-2. Fritzing diagram for a logic tester with an RGB LED
Upload the Logic Tester SketchWith the Logic Tester built, it’s time to upload the sketch. As shown in
Example 15-1, the sketch operates an RGB LED using a pushbutton switch and two
fixed resistors. Here are the steps you’ll need to follow:
1. Attach the Arduino to your computer using a USB cable.
2. Open the Arduino software and type Example 15-1 into the software’s texteditor.
3. Upload the sketch to the Arduino.
Once the Logic Tester sketch has been uploaded to the Arduino microcontroller, the
RGB’s red LED will be on, as shown in Figure 15-1. Attaching the long test wire to
the +5VDC source on the MakerShield and pressing the pushbutton switch will allow
the RGB green LED to turn on, as shown in Figure 15-3.
Example 15-1. The Logic Tester sketch
/*
Logic Tester with RGB LED
Turns on the green LED when a logic "1" (+5V) signal is detected. The
red LED will turn on at logic "0" (0V) signal. Also, when powering up the Arduino the red LED is on.
4 May 2013
Don Wilcher
*/
Chapter 15: A Logic Tester (with an RGB LED) 133
8/18/2019 Arduino Projects Experiments Part7
14/20
8/18/2019 Arduino Projects Experiments Part7
15/20
8/18/2019 Arduino Projects Experiments Part7
16/20
Figure 15-5. The Logic Tester Fritzing circuit schematic diagram
Something to Think AboutHow can the Logic Tester be operated without a pushbutton switch?
136 Make: Basic Arduino Projects
8/18/2019 Arduino Projects Experiments Part7
17/20
8/18/2019 Arduino Projects Experiments Part7
18/20
Figure 16-1. A Logic Tester with an LCD
Let’s Build a Logic TesterBuilding this tester requires the use of an LCD. If this is your first time using an LCD,
I suggest reading Chapter 14. For help adding the 16-pin male header to the LCD,
see Figure 14-2 and Figure 14-3. The 10KΩ potentiometer’s center pin is wired to
pin number 3 of the LCD. The potentiometer’s remaining pins should be wired to
+5VDC and ground. Place the LCD onto the solderless breadboard, as shown inFigure 16-2. LCD pin numbers 1 and 2 are wired to ground and +5VDC, respectively.
Adjust the 10KΩ potentiometer contrast control for the LCD for proper pixel-square
visibility. For reference on how to do this, see Figure 14-4.
Complete the rest of the tester wiring using the Fritzing diagram shown in
Figure 16-2.
138 Make: Basic Arduino Projects
8/18/2019 Arduino Projects Experiments Part7
19/20
8/18/2019 Arduino Projects Experiments Part7
20/20
+5V source, as shown in Figure 16-3. Impress the local Makerspace by testing Ar-duino and digital electronic circuits with your Logic Tester!
Example 16-1. The Logic Tester sketch
/*
Logic Tester
LCD displays "HIGH (1)" when digital circuit signal is +5V. A "LOW (0)"
is displayed when digital circuit signal is OV.
27 April 2013
Don Wilcher
*/
// include the LCD library code:#include
// set up pins on Arduino for LCD and transistor lead:
LiquidCrystal lcd(12,11,5,4,3,2);
int xistorPin = 6;
int digitalStatus = 0; // variable for reading the digital circuit state
// initialize the transistor pin as an input and set up the LCD's number
// of columns and rows:
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("LOGIC TESTER");
pinMode(xistorPin, INPUT);
}
void loop() {
// check if digital signal is HIGH or LOW:
digitalStatus = digitalRead(xistorPin);
if (digitalStatus == HIGH) {
// if digital circuit signal is +5V, display HIGH (1):
lcd.setCursor(0,1);
lcd.print("HIGH (1) "); // display HIGH (1)
}
else {
// if digital circuit signal is 0V, display LOW (0):
lcd.setCursor(0,1);
lcd.print(" LOW (0) ");
}
}
140 Make: Basic Arduino Projects