NEMA 17 Stepping Motor (62 oz-in 5mm single shaft)
10K Trimmer Potentiometer (Through Hole)
16x2 LCD (Liquid Crystal Display)
White Prototyping Breadboard (2x30 columns of tie strips and 2x2 rows of power strips)
Clear Prototyping Breadboard (2x30 columns of tie strips and 2x2 rows of power strips)
Single Red Through Hole LED (Light Emitting Diode)
Single Green Through Hole LED (Light Emitting Diode)
Single Yellow Through Hole LED (Light Emitting Diode)
We know how to display an integer on the LCD, but there are many lines of code to do this. Let's make showing integers on
the LCD screen, and where we want to show the integer a bit more easy. First, let's see what we need to do just to show an
integer on the LCD and at a particualar location. Below is the code snippet to do this:
The itoa function takes three parameters: The integer variable, in this case, it is the TenBitValue variable that is storing
the digital value from the analog reading, the adcResult is the string, or character array variable that will store the
value of the digital reading in string form so it can be presented on the LCD, and finally, the 10 is base. The base is the
number system. The standard digital number system is in base 10 and has the single digits of 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
Base 2 would have only 2 single digit numbers: 0 and 1.
I can imagine showing numbers on the LCD all the time, so I definitely don't want to keep typing those four lines of code every
time I need to have integers on the LCD, so it's time to add to the LCD library so we only need to write a single line of code
to put integers on the LCD and include the position in that line of code as well. The parameters that will be passed in are
x and y for the location, the integer variable, and the number of digits to make room in memory for the character array. The
new function will look like the following:
To make things for straightforward, another function will be added to the library to send a string to a particular location on
the LCD since we may need this functionality as well. Then we can use this to make our integer function using that function.
Here is the function to send a string of charagers to a specific location on the LCD:
Now our send an integer function will be much easier to implement:
Here is the new and improved library file:
Here is how I use the new function within an interrupt service routine. For future reference, it is not the best programming
practice to have too many instructions within an ISR (Interrupt Service Routine) because if it takes too long, other ISRs, or
another conversion for this particualr ISR may not execute. It's best to handle the long instructions within the never ending
loop. For instance, I could set a global flag variable to equal a 1 within the interrupt and inthe never ending loop, check this
flag variable to see if it is a 1 and if so, it could execute the insgructions there instead of in the ISR.