The relationship with the Arduino system is getting better. This is usually the case with new things – the more you know about them the more comfotable they get, the more you learn about them the better things seem to go.

It’s probably in the docs somewhere but I figured out that any library added in the libraries directory of the arduino software folder gets found automagicly. And any project in the examples directory can’t be overwritten. You make a directory called something like “Projects” within the arduino folder and the relationship improves.

After a few little “blinking light” type projects I wanted to get the LCD ColorShield from Sparkfun going. After weeding out the headaches of the colorlcdshield.h and colorLCDShield.cpp have to be within the libraries folder in the arduino folder, and then I had the PHILLIPS version not the EPSON version so you change lcd.init from EPSON to PHILLIPS, it worked. Then I started playing around a bit. Figured out the color definitions are a bit messed up, maybe because of the epson to phillips change. 0,0 is the top left corner which means the rows run down veritcally, etc. etc.

I took the TestPattern sketch (that’s what projects are called in Arduino) by Jim Lindblom and using it as a base made a scope program. I found it’s easier for me to do something useful while learning, I tend to learn better that way.

It works pretty good and is a good test bed for checking out the functions available.

The setup section: inits the 3 buttons that come with the LCD shield, sets up some constants, clears the screen to white, sets an array the size of the screen to 0 and draws a base line that separates the info section from the pattern section.

Things I wanted it to do – be able to still shot a pattern and give an average voltage.

The loop section: Do a loop that reads in the voltage at pin 0 and adds that number to the total. Then get the pixel position from the screen array and set that white. Now convert the input voltage to a screen X position and store it in the array place we just set white on the screen, then set the corresponding pixel on the screen blue.

After the loop runs 5 times I update the average voltage display. If I did it too soon it looked jumpy, this smooths things out a bit. There is also the if statement that checks button 0 and if pressed stops reading and just displays the existing pattern – that’s the hold system. Next maybe be able to adjust the delay with the buttons and then the voltage range. Also a way to calibrate it would be nice. But for now, here’s a pic and the sketch:
<a href=”http://leonzak.com/wp-content/uploads/2011/08/arduinopic12.jpg”><img src=”http://leonzak.com/wp-content/uploads/2011/08/arduinopic12-300x225.jpg” alt=”” title=”arduinopic1″ width=”300″ height=”225″ class=”alignnone size-medium wp-image-318″ /></a>
<pre>
<span style=”color: #7E7E7E;”>/*</span>
<span style=”color: #7E7E7E;”>  TestPattern – An example sketch for the Color LCD Shield Library</span>
<span style=”color: #7E7E7E;”>  by: Jim Lindblom</span>
<span style=”color: #7E7E7E;”>  SparkFun Electronics</span>
<span style=”color: #7E7E7E;”>  date: 6/23/11</span>
<span style=”color: #7E7E7E;”>  license: CC-BY SA 3.0 – Creative commons share-alike 3.0</span>
<span style=”color: #7E7E7E;”>  use this code however you’d like, just keep this license and</span>
<span style=”color: #7E7E7E;”>  attribute. Let me know if you make hugely, awesome, great changes.</span>

<span style=”color: #7E7E7E;”>  This sketch has example usage of the Color LCD Shield’s three</span>
<span style=”color: #7E7E7E;”>  buttons. It also shows how to use the setRect and contrast</span>
<span style=”color: #7E7E7E;”>  functions.</span>

<span style=”color: #7E7E7E;”>  Hit S1 to increase the contrast, S2 decreases the contrast, and</span>
<span style=”color: #7E7E7E;”>  S3 sets the contrast back to the middle.</span>
<span style=”color: #7E7E7E;”>*/</span>
#include <ColorLCDShield.h>
#include <stdlib.h>

<span style=”color: #CC6600;”>LCDShield</span> lcd;

<span style=”color: #CC6600;”>int</span> buttons[3] = {3, 4, 5}; <span style=”color: #7E7E7E;”>// S1 = 3, S2 = 4, S3 = 5</span>
<span style=”color: #CC6600;”>byte</span> cont = 40; <span style=”color: #7E7E7E;”>// Good center value for contrast</span>
<span style=”color: #7E7E7E;”>// save these for later things int zero = 48; int A = 65; int a = 97;</span>
<span style=”color: #CC6600;”>char</span> voltsIn[12];
<span style=”color: #CC6600;”>int</span> vin;
<span style=”color: #CC6600;”>float</span> temp;
<span style=”color: #CC6600;”>float</span> total = 0.0;
<span style=”color: #CC6600;”>int</span> screen[130];
<span style=”color: #CC6600;”>int</span> vinPoints = 1024; <span style=”color: #7E7E7E;”>// v in can be 0 to 1023.</span>
<span style=”color: #CC6600;”>int</span> screenLines = 130; <span style=”color: #7E7E7E;”>// number of lines in the screen</span>
<span style=”color: #CC6600;”>int</span> screenBottom = 98; <span style=”color: #7E7E7E;”>// leave me 2 text lines for info and text</span>
<span style=”color: #CC6600;”>int</span> useLines;
<span style=”color: #CC6600;”>int</span> scanCount = 0;
<span style=”color: #CC6600;”>int</span> scanDelay = 50; <span style=”color: #7E7E7E;”>// picked this # outa my butt</span>
<span style=”color: #CC6600;”>int</span> scanShow = 5; <span style=”color: #7E7E7E;”>// same here</span>

<span style=”color: #CC6600;”>void</span> <span style=”color: #CC6600;”><b>setup</b></span>()
{
<span style=”color: #CC6600;”>for</span> (<span style=”color: #CC6600;”>int</span> i=0; i<3; i++)
{
<span style=”color: #CC6600;”>pinMode</span>(buttons[i], <span style=”color: #006699;”>INPUT</span>); <span style=”color: #7E7E7E;”>// Set buttons as inputs</span>
<span style=”color: #CC6600;”>digitalWrite</span>(buttons[i], <span style=”color: #006699;”>HIGH</span>); <span style=”color: #7E7E7E;”>// Activate internal pull-up</span>
}
lcd.<span style=”color: #CC6600;”>init</span>(PHILLIPS); <span style=”color: #7E7E7E;”>// Initialize the LCD, try using PHILLIPS if it’s not working</span>
lcd.<span style=”color: #CC6600;”>contrast</span>(cont); <span style=”color: #7E7E7E;”>// Initialize contrast</span>
lcd.<span style=”color: #CC6600;”>clear</span>(WHITE); <span style=”color: #7E7E7E;”>// Set background to white</span>
<span style=”color: #CC6600;”>for</span> (<span style=”color: #CC6600;”>int</span> i=0; i<131; i++) {
screen[i] = 0;  <span style=”color: #7E7E7E;”>// clear the screen array so we know where we’re starting from</span>
lcd.<span style=”color: #CC6600;”>setPixel</span>(BLACK, screenBottom+1, i); <span style=”color: #7E7E7E;”>// as long as your going across, do the border line</span>
}
useLines = screenLines – (screenLines – screenBottom); <span style=”color: #7E7E7E;”>// get usable lines</span>
lcd.<span style=”color: #CC6600;”>setStr</span>(<span style=”color: #006699;”>”AV:”</span>, screenLines – (1*16), 0, BLACK, WHITE); <span style=”color: #7E7E7E;”>// static display part</span>
}

<span style=”color: #CC6600;”>void</span> <span style=”color: #CC6600;”><b>loop</b></span>()
{
<span style=”color: #CC6600;”>if</span> (<span style=”color: #CC6600;”>digitalRead</span>(buttons[0])) <span style=”color: #7E7E7E;”>// button 0 not pressed</span>
{
<span style=”color: #CC6600;”>for</span> (<span style=”color: #CC6600;”>int</span> i=0; i<130; i++) {
vin = <span style=”color: #CC6600;”>analogRead</span>(0); <span style=”color: #7E7E7E;”>// get a new reading</span>
total = total + vin; <span style=”color: #7E7E7E;”>// add it to the total so we can get an average later</span>
lcd.<span style=”color: #CC6600;”>setPixel</span>(WHITE, screen[i], i); <span style=”color: #7E7E7E;”>// clear the previous point</span>
screen[i] =  (-((<span style=”color: #CC6600;”>float</span>)vin / vinPoints) * useLines) + useLines;
lcd.<span style=”color: #CC6600;”>setPixel</span>(BLUE, screen[i], i);
}
scanCount = scanCount + 1;
<span style=”color: #CC6600;”>if</span> (scanCount > scanShow)
{
updateDisplay();  <span style=”color: #7E7E7E;”>// only update the display once in while, less screen jitter, faster loop</span>
}
}
<span style=”color: #CC6600;”>delay</span>(scanDelay);
}

<span style=”color: #CC6600;”>void</span> updateDisplay() {
temp = (<span style=”color: #CC6600;”>float</span>) ((total / (scanCount * 130)) / 1023) * 5; <span style=”color: #7E7E7E;”>// get the avg volts read</span>
dtostrf(temp, 5, 2, voltsIn);  <span style=”color: #7E7E7E;”>// make it a string</span>
lcd.<span style=”color: #CC6600;”>setStr</span>(voltsIn, screenLines-16, 3*8, BLACK, WHITE); <span style=”color: #7E7E7E;”>//display it</span>
total = 0.0;  <span style=”color: #7E7E7E;”>// now start over</span>
scanCount = 0;
}

</pre>