Skip to content

Commit 2709f63

Browse files
committed
Initial commit
0 parents  commit 2709f63

5 files changed

+100
-0
lines changed

CenterText.lib.nxc

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* CenterText.Lib.nxc
3+
*
4+
* Centers text on the NXT screen
5+
*
6+
* @author Shea Bunge <http://robotics.bungeshea.com>
7+
*/
8+
9+
int CenterText( const string text ) {
10+
int len = StrLen(text);
11+
len = (len * 5);
12+
len = (100 - len);
13+
len = (len / 2);
14+
len = (len - 5);
15+
return len;
16+
}
17+
18+
char CenterTextOut( int y, string text, unsigned long options = DRAW_OPT_NORMAL ) {
19+
int len = CenterText(text);
20+
return TextOut( len, y, text, options );
21+
}

ChooseNum.lib.nxc

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
ChooseNum.Lib.nxc
3+
*/
4+
5+
/**
6+
* ChooseNum.Lib.nxc
7+
*
8+
* Prompts the user to enter a number
9+
* using the NXT buttons.
10+
*
11+
* @uses CenterText.Lib.nxc
12+
*
13+
* @author Shea Bunge <http://robotics.bungeshea.com>
14+
*/
15+
16+
#include "CenterText.Lib.nxc"
17+
18+
int ChooseNum(string label, int y, int min, int max) {
19+
int value = (max+min)/2;
20+
while(!ButtonPressed(BTNCENTER,0)) {
21+
string msg = StrCat(label,NumToStr(value));
22+
TextOut(CenterText(msg), y, msg);
23+
if(ButtonPressed(BTNRIGHT,0)) {
24+
while(ButtonPressed(BTNRIGHT,0));
25+
value++;
26+
}
27+
if(ButtonPressed(BTNLEFT,0)) {
28+
while(ButtonPressed(BTNLEFT,0));
29+
value--;
30+
}
31+
if (value < min) value = max;
32+
if (value > max) value = min;
33+
}
34+
while(ButtonPressed(BTNCENTER,0));
35+
return value;
36+
}

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# NXC Lib
2+
A collection of useful functions and libraries written in [Not eXactly C](http://bricxcc.sourceforge.net/nxc).

ScreenPrint.lib.nxc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* ScreenPrint.Lib.nxc
3+
*
4+
* Allows you to print text on every line of the NXT
5+
* screen using only one function!
6+
*
7+
* @author Shea Bunge <http://robotics.bungeshea.com>
8+
*/
9+
10+
void ScreenPrint(string line_1, string line_2, string line_3, string line_4, string line_5, string line_6, string line_7, string line_8)
11+
{
12+
TextOut(0, LCD_LINE1, line_1);
13+
TextOut(0, LCD_LINE2, line_2);
14+
TextOut(0, LCD_LINE3, line_3);
15+
TextOut(0, LCD_LINE4, line_4);
16+
TextOut(0, LCD_LINE5, line_5);
17+
TextOut(0, LCD_LINE6, line_6);
18+
TextOut(0, LCD_LINE7, line_7);
19+
}

lib.nxc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* NXC Lib
3+
* A library of functions and macros to use in your programs.
4+
* Use NXT Lib in your program by adding the line #include "lib.nxc" to the start of the program.
5+
*/
6+
7+
/******************* Macros *****************/
8+
9+
#define Data(x, y, txt1, num, txt2) TextOut(x, y, StrCat(txt1, NumToStr(num), txt2))
10+
11+
/******************* Functions *****************/
12+
13+
int rotations(int degrees); // Change rotations to degrees
14+
int degrees(int rotations); // Change degrees to rotations
15+
16+
int rotations(int degrees) {
17+
return (degrees / 360);
18+
}
19+
20+
int degrees(int rotations) {
21+
return (rotations * 360);
22+
}

0 commit comments

Comments
 (0)