haha, I’ll drink one as well… for the cause of course.
Thinking aloud …
Take the time (in whole msecs) and do a modulo 10 on it, then test that result (= the remainder aka the least significant digit) to see if it’s <5. If it is then you can divide the time by 10 and truncate that result to get an XXXX time (now in centisecs, not exactly a common unit). If the remainder is >=5 then divide by 10 and truncate the result and then add 1 to get rounded up result (in centisecs). Now it’s a matter of divying up the XXXX result into XX.xx parts. That’s simple enough, convert that number into a char array. Now you’ve got 4 characters which you can access by an index. A new string object can be made from char(0),char(1),“.”,char(2),char(3) … which is the rounded time converted from whole msecs to XX.xx secs and then converted to a string swhich can be added to the prior string saying "Time is ". The trick will be to handle cases when the XX.xx result is more like X.xx or even 0.xx. You’ve got to be careful with the indexing.
I think. Looks kinda hacked but I’ll drink some more on it and see if something better comes to mind.
A 4 line LCD can be driven by 6 lines or by 3 if you want to use a shift register, something like the 74HC595. Ultimately I will use that chip on my project.
Dan
when you say it can be driven by 6 or 3 lines do you mean 6 or 3 pins? I’m a noob.
sspbass:
when you say it can be driven by 6 or 3 lines do you mean 6 or 3 pins? I’m a noob.
I believe that’s 6 pins … or 3 if you use a shift register. But the latter option would have to preclude you from using a standard library.
I wonder if the SF 20x4 LCD can use the same 6 pins you’re presently using and if so, why does it say 11 are needed on the product page ?
i thought that was the point of using a serial lcd, so you could control it with only a couple pins. Am I missing something?
ETA: Great! My lcd isn’t working anymore. It’s lit up but nothing is showing up and everything is still hooked up. This ought to be fun.
Give this a try when you get a chance. It’s a 1’st shot at converting and rounding the msec time values into centisec values and sending that odd number to the display. I’m not at all sure it’ll compile or if it does, that the Stream function will append the result properly. But if it works post another vid and see if you can get the run/stop LED in the shot as well. If it works then converting the centisec result to a character array and inserting a decimal point in the proper place should be do-able.
void FormatData()
{
// routine to format lines of data to be sent to LCD
// presently assume 2 lines of 16 characters
// switch formatting done based on display state
switch (DisplayState)
{
case 1:{
//this is for single A shooter
String tmp = "A: # hits = ";
// for loop to create the proper number of padding spaces
// tmp holds 12 characters
// need 3 or less spaces to pad so hit count is right justified
// 3 spaces for hits 0-9, 2 spaces for 10-99, 1 space else
//for (int i=3; i >= sizeof(char(A_count)); i--)
//{
//tmp = tmp + ' '; // add space to end of existing string
//}
// display number of hits so far
Line1 = tmp + A_count ;
// print the time of last hit in secs
String tmp2 = "Time is ";
Line2 = tmp2 + int(((A_Times[A_count-1])+5)/10);
break;}
case 2:{
// this is for A vs B mode
// put that display code here
break;
default:
// do the default =0 for now
// 2 string objects for lines 1 and 2
Line1 = "Arduino timer v1";
Line2 = "says Hello World";}
}
}
What I hope will happen is that int(((A_Times[A_count-1])+5)/10) will
-
add 5 msec to the most recent whole msec time. This will end up being similar to adding 1/2 and truncating to get a rounded result
-
divide by 10 to get into centisecs as we want the display to read to .01 sec resolution
-
truncate the FP result above by converting to an integer that the String add function can work with.
I’m not sure that converting the FP to an integer “inline” will be OK with the add/append function. We’ll see.
sspbass:
ETA: Great! My lcd isn’t working anymore. It’s lit up but nothing is showing up and everything is still hooked up. This ought to be fun.
Gotta be a loose wire. Unless it’s a 3.3V display and you’ve been using 5V signals. Was it you I was warning about this or someone else ?
I think you did but it was b/c I accidentally posted the wrong link. This is a 5 volt display.
It quit working after I secured everything to a chunk of polycarbonate to keep it all together.
i would agree that something is loose but I can’t find the culprit. I checked every connection.
I may have to just unwire it all and start over to make sure.
sspbass:
I may have to just unwire it all and start over to make sure.
BTDT. :doh:
sspbass:
Tadaa!
Excellent ! OK, let’s do an experiment to see if the String add function works like I hope it does (though I’ve not seen an example of it doing exactly this type of concatentation). Try this and see if Line2 looks like :
-
the number of digits in the centisec time display
-
Time =
-
the centisec display (as before but now it’s being added as a char array)
void FormatData()
{
// routine to format lines of data to be sent to LCD
// presently assume 2 lines of 16 characters
// switch formatting done based on display state
switch (DisplayState)
{
case 1:{
//this is for single A shooter
String tmp = "A: # hits = ";
// for loop to create the proper number of padding spaces
// tmp holds 12 characters
// need 3 or less spaces to pad so hit count is right justified
// 3 spaces for hits 0-9, 2 spaces for 10-99, 1 space else
//for (int i=3; i >= sizeof(char(A_count)); i--)
//{
//tmp = tmp + ' '; // add space to end of existing string
//}
// display number of hits so far
Line1 = tmp + A_count ;
// print the time of last hit in secs
//String tmp2 = " Time is ";
int k = sizeof(char(int(((A_Times[A_count-1])+5)/10)));
String tmp2 = char(int(((A_Times[A_count-1])+5)/10));
Line2 = k + " Time = " + tmp2 ;
break;}
case 2:{
// this is for A vs B mode
// put that display code here
break;
default:
// do the default =0 for now
// 2 string objects for lines 1 and 2
Line1 = "Arduino timer v1";
Line2 = "says Hello World";}
}
}
If this works it means i can build up a char array, adding a decimal point in the proper place, and add that to a "Time = " string. I don’t know how to do that yet but I’m sure if can be done.
Forget the above. Here is something I think just might work. I read through the following …
http://arduino.cc/en/Tutorial/StringCharacters
http://arduino.cc/en/Tutorial/StringLengthTrim
… and I think I’ve used the proper commands to do what I needed to do, add a “.” between the secs and tenths of secs digits. So long as hit times are less than 99.995 secs, it should space OK. Assuming it even compiles and displays. Hopefully by not mixing chars and Strings I’ve kept things simple and so, short of some typing error or simple doh, it’ll display nicely ! If it works then compare the displayed times to the whole msec times sent to the PC to make sure the rounding is working properly (actually you can do this w/o the following code changes).
And of course, vid or it didn’t happen !
(assuming it even runs) :shifty:
void FormatData()
{
// routine to format lines of data to be sent to LCD
// presently assume 2 lines of 16 characters
// switch formatting done based on display state
switch (DisplayState)
{
case 1:{
//this is for single A shooter mode
// display number of hits so far
String tmp = "A: # hits = ";
Line1 = tmp + A_count;
// now display the time of last hit in secs out to hundreths of secs
String tmp2 = int(((A_Times[A_count-1])+5)/10; // round msecs into csecs
int k = tmp2.length(); // k will be index to last char in padded string
int km1 = k-1; // km1 will be index to next to last char
int km2 = k-2; // km2 will be position of period
tmp2 = tmp2 + '0'; // pad the end of the truncated string with a zero
//now move chars to make space to add a period
tmp2.setCharAt(k, tmp2.charAt(km1)); // move next-2-last to last position in string
tmp2.setCharAt(km1, tmp2.charAt(km2)); // move char to next-2-last position
// now insert period
tmp2.setCharAt(km2, '.');
// tmp2 now holds rounded time in secs XX.xx format
Line2 = "Hit time = " + tmp2 ;
break;}
case 2:{
// this is for A vs B mode
// put that display code here
break;
default:
// do the default =0 for now
// 2 string objects for lines 1 and 2
Line1 = "Arduino timer v1";
Line2 = "says Hello World";}
}
}
I will try this as soon as I get home.
In the meantime, this vid http://vimeo.com/18764710
shows that newhaven display interfacing with only 2 pins, correct?
Mee_n_Mac:
I believe that’s 6 pins … or 3 if you use a shift register. But the latter option would have to preclude you from using a standard library.I wonder if the SF 20x4 LCD can use the same 6 pins you’re presently using and if so, why does it say 11 are needed on the product page ?
Actually the latest LCD library allows you to use a shift register. I was staring at it all day Saturday while I beat my head on a wall trying to steal the initialization routine!
The controller on the 20x4 is a HD44780 compatible module. You can definitely run it in 4 bit mode with 6 connections (4 bits data, 1 line for command/data selection, 1 line for the enable pin).
https://bitbucket.org/fmalpartida/new-l … /wiki/Home - Check out the HW Schematics on this page. You can even get down to 2 pins on the shift register if you truly wanted to. Ultimately my LCD will move to a small board connect by 5 wires. Vcc, Ground, Clock, Data and Enable. I may add a 6th, backlight enable.
Dan
sspbass:
I will try this as soon as I get home.In the meantime, this vid http://vimeo.com/18764710
shows that newhaven display interfacing with only 2 pins, correct?
It is using a set of serial lines, so correct, only two lines.
Dan
why deal with a shift register when you can just use a set of serial lines?
ETA: I am also attaching a synopsis for what I had envisioned for modes. I’m not 100% sure how to handle shooters using multiple targets. For now this is probably sufficient.
Inherently the HD44780 series of controllers (and clones) is not serial, but parallel. Anything serial has additional circuity added to it which drives up the cost. For instance, I bought cheap 2x16 line displays on eBay for about $4/display. The shift registers, $0.50/chip. So now I have displays that I can drive with 2 lines (or 3) for a little under $5/unit. So now I can drive, with 3 lines, 1 lcd. Technically I can easily expand this to drive many more LCDs by simply adding more shift registers and tying together enable pins.
Dan
what doesn’t it like here?
sspbass:
what doesn’t it like here?
My first look says it’s simply a typo. I forgot to include a closing ).
String tmp2 = int(((A_Times[A_count-1])+5)/10; // round msecs into csecs
… should be …
String tmp2 = int(((A_Times[A_count-1])+5)/10); // round msecs into csecs
If the compiler still chokes then it may be a little wierdness by the compiler. Previously it had no problem concatenating that statement (a non-String object) with a String object.
Line2 = tmp2 + int(((A_Times[A_count-1])+5)/10);
So I wonder if doing some intermediate step would help resolve any confusion. Try this rev if the above closing parenthesis doesn’t work. I use and then reuse the local variable k.
void FormatData()
{
// routine to format lines of data to be sent to LCD
// presently assume 2 lines of 16 characters
// switch formatting done based on display state
switch (DisplayState)
{
case 1:{
//this is for single A shooter mode
// display number of hits so far
String tmp = "A: # hits = ";
Line1 = tmp + A_count;
// now display the time of last hit in secs out to hundreths of secs
int k = int(((A_Times[A_count-1])+5)/10); // round msecs into csecs
String tmp2 = k // convert result above into a String
k = tmp2.length(); // k will be index to last char in padded string
int km1 = k-1; // km1 will be index to next to last char
int km2 = k-2; // km2 will be position of period
tmp2 = tmp2 + '0'; // pad the end of the truncated string with a zero
//now move chars to make space to add a period
tmp2.setCharAt(k, tmp2.charAt(km1)); // move next-2-last to last position in string
tmp2.setCharAt(km1, tmp2.charAt(km2)); // move char to next-2-last position
// now insert period
tmp2.setCharAt(km2, '.');
// tmp2 now holds rounded time in secs XX.xx format
Line2 = "Hit time = " + tmp2 ;
break;}
case 2:{
// this is for A vs B mode
// put that display code here
break;
default:
// do the default =0 for now
// 2 string objects for lines 1 and 2
Line1 = "Arduino timer v1";
Line2 = "says Hello World";}
}
}
But I’d hope fixing the typo would resolve the problem.