krotchrome.blogg.se

How to use robotc
How to use robotc





how to use robotc

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++)

#How to use robotc 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.

how to use robotc

%g – Signed float, but will print as either standard %f or %e, depending on which is shorter.The following modifiers are not currently working (as of 30 march 2013) but are due to be fixed soon %X – unsigned hex int or long (upper case, e.g.%x – unsigned hex int or long (lower case, e.g.%d – a signed or unsigned long or int *.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.







How to use robotc