-
• #2
Using
var char = data.substr(i, 1);
seems to work. -
• #3
Finally found it! Try data.charAt(i) instead of data.charAt[i], or simply data[i] :)
-
• #4
doh! I used brackets instead of parentheses.
data.charAt(i);
works.Code:
s7s.prototype.sendValue = function (data) { var a = this.address; var clr = this.displayTable.Clear; //Display clear command var dpc = this.displayTable.dp.cmd; //Decimal point command var dplo = this.displayTable.dp.location; //Decimal point location map var i; var length = data.length; var dpLoc; var value = ""; for(i=0; i<length; i++) { var char = data.charAt(i); if(char != ".") { value += char; } if(char == ".") { dpLoc = i; } } I2C1.writeTo(a, clr); //Clear display I2C1.writeTo(a, value); if(typeof dpLoc !== 'undefined') { I2C1.writeTo(a, dpc); I2C1.writeTo(a, dplo[dpLoc - 1]); } };
-
• #5
Two thoughts:
if (char != ".") { value += char; } else { dpLoc = i; }
'data' always has a decimal point?
I2C1.writeTo(a, dpc); if(typeof dpLoc !== 'undefined') { I2C1.writeTo(a, dplo[dpLoc - 1]); }
-
• #6
No, results don't always have to return in a decimal format, however, in this case they will. I have
if(typeof dpLoc !== 'undefined')
For the moments where I wont, for example, taking a PPM reading of a solution. That was my attempt to write a generic function to output a result to my 4 - digit 7 segment display. -
• #7
Doh, I get it now, wasn't reading carefully enough and missed the two I2CI.writeTo()'s before the decimal point check, sorry, my bad!
-
• #8
If data is 1234 and there is no decimal point in the value, the display will only show 1234. I still have to add checks for how many digits and if the display comma needs to be enabled or not. For example, 25.2'C. I have an idea:
code:if (char == "'") { I2C1.writeTo (a,0b00001000); //turn on comma}
-
• #9
yeah, sorry, I just realized that and edited my comment, sorry :)
I am not sure why I am receiving undefined when I loop through data which is a string, To see if data contained a string I did console.log(typeof data + ": " + data); which echoed out String : 26.19. From my understanding, I thought looping through the data string and using charAt[i] I should in theory return the character at i, however, I am receiving undefined. Why is that and how do I return the character at i?