Index into a table or array.
value = arrayName[index];
byte arrayName[] = {0,2,5,9,13,15,}; // 6 elements from arrayName[0] to arrayName[5]
say index was then 4, received from a Serial.read() perhaps.
value = arrayName[index] =arrayName[4] = 13 with the first element at location 0 and the 4th at location 5.
If you want to use a letter as the index into an array, you need to consider the numeric vale of the letter, and reduce the offset to zero (to eliminate empty space). or some other mechanism to generate the array lookup value.
No. No not really. Are you formatting output? If you're using a string table to format output then you'll waste a great deal of RAM. Most of it sitting with 0s in it. Why can't you just use the inches variable? What type is it?
No. No not really. Are you formatting output? If you're using a string table to format output then you'll waste a great deal of RAM. Most of it sitting with 0s in it. Why can't you just use the inches variable? What type is it?
Yea formatting the output. Can't work out how to do it and most of the people I talked to say it is complicated.
So though this way would be easier as A = 1 and so on.
int feet = inches / 12 ; //divides inches by 12, discards any remainder and puts the result in the feet variable (integer division)
inches %= 12 ; //divides inches by 12 and puts the remainder in the inches variable (modulo operator)
int feet = inches / 12 ; //divides inches by 12, discards any remainder and puts the result in the feet variable (integer division)
inches %= 12 ; //divides inches by 12 and puts the remainder in the inches variable (modulo operator)
Ah I get it now and that works.
Trying to format it using SprintF but getting a load of garbage in the serial out.
// UKHeliBob's math to work out Feet and Inches seperatly
int feet = inches / 12 ; //divides inches by 12, discards any remainder and puts the result in the feet variable (integer division)
inches %= 12 ; //divides inches by 12 and puts the remainder in the inches variable (modulo operator)
// Test to see if above math works.
// Serial.print("ft, ");
// Serial.println (feet) ;
// Serial.print("in, ");
// Serial.println (inches) ;
// Format Feet and Inches from above into a buffer variable, then print via serial.
int buffer;
sprintf (buffer, "%02d%02d", feet, inches);
Serial.print (buffer);