NxtDispla圜enteredTextLine(4, "0x%08X", foo) NxtDispla圜enteredTextLine(2, "0x%08X", pie) I am a big fan of the %X modifier to display data but to make it obvious that it’s a hex number I like to add the 0x to it and make sure they have leading zeroes, so all line up nicely on the screen: task main() The actual value of the float has not been changed, only the number of digits that are being displayed. NxtDispla圜enteredBigTextLine(4, "%.2f", pie) So how do we do that? Take a look: task main() When we print that out, we’re actually only interested in displaying the first 2 numbers after the decimal point. Consider the following: float pie = 3.1415926535 You can do some pretty cool things with them. Play with it and see which ones work and which ones don’t. The leading zeroes thing will also work with some of the other types. It should something like this after a little while: NxtDispla圜enteredBigTextLine(4, "%05d", counter++)
ROBOTC FUNCTIONS CODE
The following piece of code will simply count upwards from 0 and display a 5 digit number with leading zeroes: task main() Using the output modifiers you can achieve the same. Say you were making a tacho counter, like in your car (not the Mexican restaurant), you would want the number of digits displayed to be the same. So what else can you with these to change the way your printed variables look? %G – Signed float, but will print as either standard %f or %E, depending on which is shorter.
I’ve marked the ones I use with an asterisk (*) Here’s a complete list of all of the ones supported by ROBOTC. NxtDisplayTextLine(5, "%3d cherries", num_cherries) ĭoesn’t that look much better? The cool thing is, there are lots of output modifiers, the bad thing is, there are lots of output modifiers! Sometimes it can get a little confusing, so I’ll stick with the most commonly used ones (by me, anyway). NxtDisplayTextLine(4, "%3d pears", num_pears) NxtDisplayTextLine(3, "%3d apples", num_apples) When you’ve figured it out, run it and check out the results. Take a look at the next program and see if you can spot the subtle difference. What if there was a way to get the firmware to take care of that stuff for you? Int num_apples = 0 // how do you like them apples?ĭoesn’t it get super annoying to see those lines jumping back and forth, depending on whether it’s a 1, 2 or 3-digit number? You work around it by checking how many digits the number is long and printing some spaces in front of the number but that would be cumbersome and would only make your code look cluttered. However, consider the scenario when the number of items change rapidly, what do you think will happen to the words “apples”, “pears” and “cherries”? try the program below and you’ll see what I mean: task main()
The items are not arranged very neatly and most of the time that doesn’t really matter that much. The screen will look something like the one below, which is fine if you don’t care about layout. NxtDisplayTextLine(5, "%d cherries", num_cherries) NxtDisplayTextLine(4, "%d pears", num_pears) NxtDisplayTextLine(3, "%d apples", num_apples) NxtDispla圜enteredTextLine(1, "Fruit Stand") Int num_apples = 10 // how do you like them apples? Your code may, or may not have looked something like this: task main() If you’ve ever had to output anything on the screen in ROBOTC, you’ve probably used nxtDisplayTextLine() or one of its many siblings.