The original idea was to create a library that simplify the use of IC 74HC595 between Arduino and other hardware. In this Instructable I will share this to you using as example the control of a 16x2 LCD.
The example will show on the LCD the seconds that has passed since Arduino was restarted.

I hope it will be useful to you.

What do you need for THIS example?
- Arduino
- Arduino IDE installed
- One IC 74HC595
- One 4.7Kohm resistor or similar
- One "104" capacitor
- Wires!

Step 1: Place the Library Under Arduino Folder

I've named the library "ShiftOut". It goes under %arduino-directory%/hardware/libraries

This one is the library that I've programmed. Comments are welcome.

Step 2: LCD Library

The second library needed is the one that communicate to the LCD. I've used this one and not the one that came with Arduino because it's an initialisation bug.

It's based on www.slashdev.ca/arduino-lcd-library/ and has the necessary changes to integrate the ShiftOut Library that I made.

This must be uncompressed under %arduino-directory%/hardware/libraries too.

Step 3: Open Arduino IDE

Now it's time to write the code. Open Arduino IDE and write this:

#include <Lcd.h>

ShiftOut sOut(8, 12, 11, 1);
Lcd lcd = Lcd(16, FUNCTION_4BIT | FUNCTION_2LINE | FUNCTION_5x11, &sOut);
void setup()
  lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS->1, RW->2, E->3
  lcd.set_data_pins(_4PINS(4,5,6,7)); // D4->4, D5->5, D6->6, D7->7
void loop()
  lcd.print((long)millis() / 1000);

This simple sketch shows on the LCD the seconds that has passed since Arduino was restarted.

Step 4: Compilation

It's important that the libraries are copied before Arduino IDE is open. Otherwise the compilation could fail.

If everything was OK, you could connect Arduino to a 74HC595 and this one to a LCD following the schematic images diagrammed using Fritzing.

The connection should be as follow:

Step 5: Run the Sketch on Arduino

If everything is connected right, you should see the counting seconds on the LCD.

Step 6: Conclusion

I hope this library will be useful for someone. It's to me because the Arduino code gets simple and nice, without filling it with collateral coding messing the sketch main purpose.


Step 7: Bonus Track: Another Example

Here is Arduino using ShiftOut to control two seven segment displays in cascade:

More info could be found here: http://gusps.blogspot.com/

Hi,<br>Having problems compiling this script example.<br>I might have missed something vital?<br>Have the libraries saved in the location specified.<br>Using Arduino UNO R3 and 1.0 IDE<br><br>Here are the error messages...<br>Its probably something simple on my part but can't work out what it is.<br><br>Any help appreciated.<br><br>Thanks<br>Struggler<br><br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:26:27: error: WConstants.h: No such file or directory<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::send(uint8_t, uint8_t)':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:65: error: 'delay' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::set_enable(uint8_t)':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:113: error: 'delayMicroseconds' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::pulse_enable()':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:119: error: 'HIGH' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:120: error: 'delayMicroseconds' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:121: error: 'LOW' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::check_bf()':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:131: error: 'INPUT' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:136: error: 'HIGH' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:137: error: 'digitalRead' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:138: error: 'LOW' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:148: error: 'OUTPUT' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::setup()':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:174: error: 'OUTPUT' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:180: error: 'OUTPUT' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:186: error: 'delay' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:195: error: 'delayMicroseconds' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:206: error: 'delayMicroseconds' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::dWrite(uint8_t, uint8_t)':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:348: error: 'digitalWrite' was not declared in this scope<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp: In member function 'void Lcd::pMode(uint8_t, uint8_t)':<br>C:\arduino-1.0\libraries\Lcd\Lcd.cpp:355: error: 'pinMode' was not declared in this scope<br>
Hi. It seems that the installation have some issues. Does other projects work well?<br>If &quot;yes&quot;, maybe this instructions are not compatible with Arduino UNO R3. I remember to did this with Arduino 0015 or 0017. Try to use it instead.<br><br>Maybe other user can confirm if this works on Arduino UNO IDE.<br><br>I'll do the tests one of these days and tell you if it worked.<br><br>Thanks.
Thanks to your instructable (This one) I've managed to follow it to the letter and I've produced this.<br> <br> Thank you
Oww!!... Thanks!. I really apreciate your comment. Makes me willing to do another instructable ;p<br><br>Regards!...<br><br>
The Code provided up above gives me an error, while compiling/verifying. Please Help.
I meant in Step 3, of this tutorial.
Hi marker4455. Which error do you get?
I've Forgot to mention that I'm using arduino 0022.
I guess that the IDE version doesn't matter in this case.<br><br>Can you explain the problem with some more details?<br>Thanks.
I've built a simple header for this project and everything seems to be fine, it works perfect. However, when using ONLY the 5v power supply, it don't work out - in this case the arduino is not connected to the PC. I saw your comment about the initialization bug in the original liquid crystal library and I'm wondering if it's not the cause of this issue ...<br><br>Please?
But, are you powering Arduino with an external 9v and using 5v regulated from Arduino?
Just wondering if you could do a more advanced version of this tutorial, say for example hooking up a keypad to the LCD display.
Hello, please correct the first line <br>wich says: #include &lt; Lcd.h&gt;; <br>must says: #include WITHOUT THE SPACE :)<br><br>Thanks for your work<br><br>sorry for my english
Done!<br>Thanks for telling....
I'm trying to follow this instructable, but you've forgotten to list the wire diagram, what pin connects to what wire on the LCD screen?<br><br>I would love to include this in a huge project I currently have planned, but without the pin layout I will have to guess at it.
Hi.<br>It's on the 4th step, 2nd image.
I managed to get it to work, thanks for taking the time and effort to help me, when I do my big project I'll acknowledge you in the credits
The image is from left to right, pin1 to last pin on the LCD. Look for the comment below about the type of LCD i've used.<br>Let me know if that help you...
is it posible to use custem characters with this librarie<br /> cus i cant get it to work....
I haven't tried it.<br /> <br /> I remember that the original lib can do that. Check&nbsp;<a href="http://www.slashdev.ca/arduino-lcd-library/" rel="nofollow">www.slashdev.ca/arduino-lcd-library/</a><br />
i just found out how to do that<br /> example code below<br /> <br /> but now a new problem accurs<br /> when i use the funktion &quot;FUNCTION_2LINE&quot;<br /> the tekst becomes fage and vaded<br /> how to fix it<br /> <br /> <br /> <br /> <p>/*<br /> &nbsp;* Define custom characters for creating an animation<br /> &nbsp;*/<br /> #include &lt;Lcd.h&gt;<br /> #include &lt;ShiftOut.h&gt;</p> <p><br /> ShiftOut sOut(8,12,11,2);</p> <p>Lcd lcd = Lcd(16, FUNCTION_4BIT, &amp;sOut);</p> <p>int potPin = 0;&nbsp;&nbsp;&nbsp; // select the input pin for the potentiometer<br /> int val = 100;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variable to store the value coming from the sensor<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //set to 100 for when there</p> <p>uint8_t smile[] = {0x00,0x0A,0x00,0x11,0x0E,0x00,0x00,0x00};<br /> uint8_t stripe[] = {0x13,0x06,0x0C,0x19,0x13,0x06,0x0C,0x19};<br /> uint8_t stripe1[] = {0x19,0x13,0x06,0x0C,0x19,0x13,0x06,0x0C};<br /> uint8_t stripe2[] = {0x0C,0x19,0x13,0x06,0x0C,0x19,0x13,0x06};<br /> uint8_t stripe3[] = {0x06,0x0C,0x19,0x13,0x06,0x0C,0x19,0x13};</p> <p>&nbsp;</p> <p><br /> void setup()<br /> {<br /> &nbsp;</p> <p>&nbsp; // set pin assignment<br /> &nbsp; lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS-&gt;1, RW-&gt;2, E-&gt;3<br /> &nbsp; lcd.set_data_pins(_4PINS(4,5,6,7)); // D4-&gt;4, D5-&gt;5, D6-&gt;6, D7-&gt;7<br /> &nbsp; <br /> &nbsp; lcd.setup(); // setup arduino and initialize LCD<br /> &nbsp;&nbsp;&nbsp; lcd.clear();<br /> &nbsp; // define the custom characters<br /> &nbsp; lcd.define_char(0, smile);<br /> &nbsp; lcd.define_char(1, stripe);<br /> &nbsp;&nbsp;&nbsp; lcd.define_char(2, stripe1);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcd.define_char(3, stripe2);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcd.define_char(4, stripe3);</p> <p><br /> }</p> <p>void loop()<br /> {<br /> &nbsp; val = analogRead(potPin);<br /> &nbsp; lcd.home();<br /> &nbsp; lcd.print((char)1);&nbsp;&nbsp;&nbsp;<br /> &nbsp; delay(val);<br /> &nbsp; lcd.clear();<br /> &nbsp;&nbsp;&nbsp; lcd.print((char)2);&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay(val);<br /> &nbsp; lcd.clear();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcd.print((char)3);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay(val);<br /> &nbsp; lcd.clear();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcd.print((char)4);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; delay(val);<br /> &nbsp; lcd.clear();</p> <p>}</p>
i feel like 2 things a nerd and a idiot<br /> <br /> how do i put tekst on the second line?
never mind found it out<br /> <br /> lcd.move_to(0, 2);<br /> <br /> that is the code<br /> <br /> lcd.move_to(0 collum , 2 row);
Hi.<br /> <br /> Im Living in Germany and I cant find an 74HC595.<br /> Could i use your ShiftOut Library with a 4014?<br /> Its' an 8-Bit Shift Register,too. I Think the Connection-Layout is a Little bit different.<br /> <br /> <br />
order a few in holland or on ebay<br /> <br /> i found some that work<br /> <br /> and it is like 50 km over the german border
I don't know but on Ebay you could find 10 pcs of 74HC595 for about 3 USD (2,2 &euro;) fdp in
Thanks.<br />
Just a word of warning. Lots of times the electronic parts on eBay come from China or something and actually aren't what they advertise. Here's a link that sort of explains what I'm saying. <a href="http://www.businessweek.com/magazine/content/08_41/b4103034193886.htm?chan=magazine+channel_top+stories" rel="nofollow">Dangerous Fakes</a><br /> <br /> Even the <a href="http://www.bunniestudios.com/blog/?p=918" rel="nofollow">Chumby</a> had problems.<br />
I'm not sure. Check the Input Voltage and the layout. Send me a link to datasheet. I don't know what is that component.<br />
The Pin Layout isnt the same.<br /> <br /> http://www2.produktinfo.conrad.com/datenblaetter/150000-174999/172707-da-01-en-MC_14014_CD_4014_MC_14021_CD4021.pdf<br />
No, it won't work. You need a Serial In, Parallel out.<br /> Alternatives are: MC54/74HC164, 74LS595 and CD4094.<br /> <br /> Check the layout though.<br />
Thanks.<br />
i have 2 questions<br /> <br /> 1: what is the type of lcd you use<br /> 3:what happened to 2<br /> 4:could a second 74HC595 be added to drive led<br /> <br /> so i mean a lcd and 4 or 7 leds?
1) It's a 16x2, and has a label on back that reads &quot;WINSTAR ELWH1602C-YGB-STK&quot;<br /> 2) ?????<br /> 3) Yes, it will work. The main purpose was simplify the use of PINs beside a 595.<br />
so when i conect a second 595 on the way like this<br /> <a href="http://www.arduino.cc/en/Tutorial/ShiftOut" rel="nofollow">http://www.arduino.cc/en/Tutorial/ShiftOut</a><br /> <br /> then i could program some leds in it<br /> <br /> that would be cool<br /> i am building the starting chip for a turbine engine<br /> <br /> but the data panel (it shows if evrything is working) would have 10 cables if you did not show me your way&nbsp; <br /> <br /> thank you
Yes, it will work.<br /> You'll have to adapt some code, but if u are a programmer will not have any problem.<br /> You can see this video that is about connecting 2 595 in cascade and using the ShiftOut Library I made:<br /> http://www.youtube.com/watch?v=dCAitY5223c<br /> <br /> Here is the base code. It's not a reflect of the video, but it's a similar routine:<br /> <br /> #include &lt;ShiftOut.h&gt;<br /> <br /> ShiftOut Reg1(8,12,11,2);<br /> <br /> void setup()<br /> {<br /> &nbsp; delay(1000);<br /> }<br /> <br /> void loop()<br /> {<br /> &nbsp; for (int j = 0; j &lt; 16; j++)<br /> &nbsp; {<br /> &nbsp;&nbsp;&nbsp; Reg1.digitalWrt(j, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(100);<br /> &nbsp;&nbsp;&nbsp; Reg1.digitalWrt(j, LOW);<br /> &nbsp; }<br /> <br /> &nbsp; for (int j = 15; j &gt;= 0; j--)<br /> &nbsp; {<br /> &nbsp;&nbsp;&nbsp; Reg1.digitalWrt(j, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(100);<br /> &nbsp;&nbsp;&nbsp; Reg1.digitalWrt(j, LOW);<br /> &nbsp; }<br /> }<br /> <br /> I hope it's clear for you. If not, just let me know and I'll help you.<br /> <br /> Regards.<br />
<p>i made a small script that uses an lcd- 1 button-4 led's-2 595's<br /> and here is it's script<br /> <br /> #include &lt;Lcd.h&gt;<br /> #include &lt;ShiftOut.h&gt;<br /> #include &quot;Servo.h&quot;</p> <p>Servo gasservo;</p> <p>ShiftOut sOut(8,12,11,2);<br /> Lcd lcd = Lcd(16, FUNCTION_4BIT | FUNCTION_2LINE | FUNCTION_5x11, &amp;sOut);</p> <p>int switchPin = 4;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // switch is connected to pin 2</p> <p>&nbsp;</p> <p>int val;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variable for reading the pin status<br /> int val2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variable for reading the delayed status<br /> int buttonState;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // variable to hold the button state</p> <p>int lightMode = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // What mode is the light in?</p> <p>void setup() {<br /> &nbsp; pinMode(switchPin, INPUT);&nbsp;&nbsp;&nbsp; // Set the switch pin as input<br /> &nbsp;&nbsp;&nbsp; lcd.set_ctrl_pins(CTRLPINS(1,2,3)); // RS-&gt;1, RW-&gt;2, E-&gt;3<br /> &nbsp; lcd.set_data_pins(_4PINS(4,5,6,7)); // D4-&gt;4, D5-&gt;5, D6-&gt;6, D7-&gt;7<br /> &nbsp;<br /> &nbsp; lcd.setup();<br /> &nbsp; <br /> &nbsp; lcd.clear();<br /> &nbsp; gasservo.attach(5); <br /> &nbsp; Serial.begin(9600);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Set up serial communication at 9600bps<br /> &nbsp; buttonState = digitalRead(switchPin);&nbsp;&nbsp; // read the initial state<br /> }</p> <p>void loop(){<br /> &nbsp; val = digitalRead(switchPin);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // read input value and store it in val<br /> &nbsp; delay(10);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 10 milliseconds is a good amount of time<br /> &nbsp; val2 = digitalRead(switchPin);&nbsp;&nbsp;&nbsp;&nbsp; // read the input again to check for bounces<br /> &nbsp; if (val == val2) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // make sure we got 2 consistant readings!<br /> &nbsp;&nbsp;&nbsp; if (val != buttonState) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the button state has changed!<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (val == LOW) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // check if the button is pressed<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (lightMode == 0) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // if its off<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lightMode = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // turn lights on!<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (lightMode == 1) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // if its all-on<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lightMode = 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // make it blink!<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (lightMode == 2) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // if its blinking<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lightMode = 3;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // make it wave!<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br /> &nbsp;&nbsp;&nbsp;&nbsp; if (lightMode == 3) { //&nbsp; if its waving, <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lightMode = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // turn light off!<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp; buttonState = val;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // save the new state in our variable<br /> &nbsp; }</p> <p>&nbsp; // Now do whatever the lightMode indicates<br /> &nbsp; if (lightMode == 0) { // all-off<br /> &nbsp; lcd.clear();<br /> &nbsp; lcd.home();<br /> &nbsp; lcd.print(&quot;off&quot;);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, LOW);</p> <p>&nbsp; }</p> <p>&nbsp; if (lightMode == 1) { // all-on<br /> &nbsp; lcd.clear();<br /> &nbsp; lcd.home();<br /> &nbsp; lcd.print(&quot;on&quot;);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, HIGH);<br /> &nbsp; }</p> <p>&nbsp; if (lightMode == 2) { // blinking<br /> &nbsp; lcd.clear();<br /> &nbsp;&nbsp;&nbsp; lcd.home();<br /> &nbsp; lcd.print(&quot;blink&quot;);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, HIGH);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(100);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, LOW);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, LOW);<br /> &nbsp;&nbsp;&nbsp; delay(100);<br /> &nbsp; }<br /> &nbsp; if (lightMode == 3)&nbsp; { // &quot;wave&quot;<br /> &nbsp; lcd.clear();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lcd.home();<br /> &nbsp; lcd.print(&quot;wave&quot;);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, LOW);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(50);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(9, LOW);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(50);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(10, LOW);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(50);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(11, LOW);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, HIGH);<br /> &nbsp;&nbsp;&nbsp; delay(50);<br /> &nbsp;&nbsp;&nbsp; sOut.digitalWrt(12, LOW);<br /> &nbsp; }&nbsp;&nbsp;&nbsp; <br /> }<br /> &nbsp;</p>
could you draw a normal diagram<br /> i have an hard time decivering your diagrams now
Have you tried opening the Fritzing file?<br />
Here is the link: http://www.megaupload.com/?d=NA9UXM4M<br />
Tnx for this. It really helped me a lot.<br />
Hi, it works very well, thanks !<br /> <br /> I've some stupid question like the last time lol :<br /> ShiftOut sOut(8, 12, 11, <strong>1</strong>);<br /> Why the PIN1 is define ?<br /> <br /> And the library is very good but have you got some function for scrolling etc ?<br />
&nbsp;&quot;1&quot; is the number of 74HC595 in cascade. You could use it to join varios in cascade an have more &quot;out&quot; PINs.<br /> <br /> The library doesn't have scrolling or other features support.&nbsp;<br /> <br /> More info in: http://GusPS.blogspot.com<br />
Thanks a lot !<br /> <br /> So for a 8 bit connection we can do something like that ?<br /> <br /> &quot;<br /> &nbsp; ShiftOut sOut(2, 3, 4, 2);<br /> &nbsp; Lcd lcd = Lcd(20, FUNCTION_8BIT | FUNCTION_2LINE | FUNCTION_5x11, &amp;sOut);<br /> &nbsp; lcd.set_ctrl_pins(CTRLPINS(1,2,3));&nbsp; // RS-&gt;1, RW-&gt;2, E-&gt;3<br /> &nbsp; lcd.set_data_pins(_8PINS(8,9,10,11,4,5,6,7)); // D4-&gt;4, D5-&gt;5, D6-&gt;6, D7-&gt;7, D1-&gt;8, D2-&gt;9, D3-&gt;10, D-&gt;11 <br /> &quot;<br /> <br /> And to define new characters :<br /> <br /> &quot;<br /> byte newChar[8] = { B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 }; <br /> <br /> void setup() { <br /> lcd.set_ctrl_pins(CTRLPINS(1,2,3)); &nbsp; lcd.set_data_pins(_8PINS(8,9,10,11,4,5,6,7)); <br /> lcd.setup(); <br /> lcd.clear(); <br /> lcd.home(); <br /> lcd.define_char(0, newChar); <br /> lcd.print(0); <br /> }<br /> &quot;<br /> <br /> ?
Well... I haven't test it with 8 bit, but It seems it would work.<br /> Have you tired it?<br /> Post your&nbsp;experiences so other can benefit too.<br /> <br /> Thanks!&nbsp;
So for the 8bit its works good with the connection on the following picture<br /> (from http://www.arduino.cc/en/Tutorial/ShiftOut)<br /> <br /> But I can't see any differences between 4bit and 8bit, we can create new characters in both mode and the refresh time seem to be the same.<br /> <br /> To create new characters, the following code didn't work :<br /> lcd.define_char(0, newChar); <br /> lcd.print(0); <br /> I've just &quot;0&quot; on the lcd display<br /> <br /> We have to do this :<br /> lcd.define_char(0, newChar);<br /> lcd.print((char)0); <br />
Thanks a lot man for this tutorial. I've waisted about half a day trying to get Arduino to write to an LCD&nbsp;through the 74HC595 and without too much success. I guess I was too tired to do it right.<br /> <br /> Nevertheless it is just great this library and, at least for myself, I will be eternally grateful :)<br /> <br /> Keep up the good work!<br />
Thanks!. I'm glad it is usefull!<br />
That's look nice, but what the value of the capacitor (in Farrad) ?<br /> And what the use of this wire (On following image) ?<br /> Sorry for the questions but I'm not an electronic king (and sorry for my english too)<br />
Lenny was right.<br /> The Cap is for decoupling. I've used 0.0000001 farads. (The common one labeled '104').<br /> Red wire: 5V power to LCD.<br />

About This Instructable




More by GusPS:LCD Shifter for Arduino 
Add instructable to: