vb.net barcode scanner programming #define LIGHT #define MOTOR in Software

Encoding Data Matrix ECC200 in Software #define LIGHT #define MOTOR

Listing 14.2
Data Matrix 2d Barcode Decoder In None
Using Barcode Control SDK for Software Control to generate, create, read, scan barcode image in Software applications.
Make Data Matrix ECC200 In None
Using Barcode generation for Software Control to generate, create Data Matrix ECC200 image in Software applications.
#define LIGHT #define MOTOR
Data Matrix Decoder In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
Data Matrix 2d Barcode Maker In Visual C#
Using Barcode generator for Visual Studio .NET Control to generate, create ECC200 image in Visual Studio .NET applications.
photophile.nqc.
Drawing ECC200 In .NET
Using Barcode generator for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
DataMatrix Printer In .NET
Using Barcode printer for .NET Control to generate, create ECC200 image in VS .NET applications.
SENSOR_1 OUT_A+OUT_C
Data Matrix ECC200 Printer In Visual Basic .NET
Using Barcode generation for .NET Control to generate, create ECC200 image in .NET applications.
Encoding EAN 13 In None
Using Barcode maker for Software Control to generate, create EAN / UCC - 13 image in Software applications.
task main() { SetPower(MOTOR, 7); SetDirection (MOTOR, OUT_REV); SetSensorType(LIGHT, SENSOR_TYPE_LIGHT); while(true) { if(LIGHT > 60) On(MOTOR); else Off(MOTOR); } }
Data Matrix ECC200 Encoder In None
Using Barcode maker for Software Control to generate, create Data Matrix ECC200 image in Software applications.
Code 128A Generation In None
Using Barcode maker for Software Control to generate, create Code 128B image in Software applications.
If you key in this program in order to try it out, name it photophile.nqc (photophile means lover of light ). Be on guard for typographical errors, and do not omit any of the brace characters! As with most C-based languages, capitalization is important. For example, while is correct, but not While.
Making Code 39 In None
Using Barcode drawer for Software Control to generate, create Code-39 image in Software applications.
Bar Code Generation In None
Using Barcode generation for Software Control to generate, create bar code image in Software applications.
EXAMINING THE NCQ PROGRAM
USD - 8 Generation In None
Using Barcode creation for Software Control to generate, create USD - 8 image in Software applications.
Encode USS-128 In Objective-C
Using Barcode maker for iPad Control to generate, create USS-128 image in iPad applications.
Let s take a closer look at this program. The first two lines:
Paint GTIN - 12 In None
Using Barcode maker for Online Control to generate, create UPC A image in Online applications.
Print Bar Code In .NET
Using Barcode drawer for Reporting Service Control to generate, create barcode image in Reporting Service applications.
#define LIGHT #define MOTOR SENSOR_1 OUT_A+OUT_C
Decode UPC-A Supplement 2 In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
Create Code-39 In Java
Using Barcode maker for Java Control to generate, create Code 3 of 9 image in Java applications.
180 PROGRAMMING THE LEGO MINDSTORMS RCX
GS1 - 12 Creator In Java
Using Barcode maker for Android Control to generate, create UPC A image in Android applications.
Encode UPC - 13 In None
Using Barcode maker for Font Control to generate, create GTIN - 13 image in Font applications.
FIGURE 14.2 The basic rover robot to be used with the programs in this chapter.
These two statements define constants (unchanging variables) used elsewhere in the program. Constants are defined by using the #define keyword followed by the name of the constant and finally by the value of that constant. Note that the value of the constants LIGHT and MOTOR are themselves constants! In this case, the constants SENSOR_1, OUT_A, and OUT_B are built-in constants, with values already defined by NQC. We use our own constants to make working with the RCX even easier. See Table 14.1 for a list of the most commonly used built-in constants. You will note that the MOTOR constant refers to two outputs, both A and C (OUT_A OUT_C). This allows us to operate both motors together, which will make it a little easier to command the robot to go forward or backward. The next two lines of the program are:
task main() {
Each NQC program can have up to 10 tasks. Each task can be run simultaneously. The task that is run when you press the Run button on the RCX is called main. You can create your own names for other tasks you add in your program, but main always refers to the, well, main task that the RCX automatically runs. Note the open brace (the { character) that follows the task main() statement. In NQC, as in C, multiple program statements are defined in blocks or compound statements. For
TABLE 14.1
NQC STANDARD CONSTANTS FUNCTION EQUIVALENT VALUE
CONSTANT NAME
SetSensor SENSOR_1 SENSOR_2 SENSOR_3 SetSensorMode SENSOR_MODE_RAW SENSOR_MODE_BOOL SENSOR_MODE_EDGE SENSOR_MODE_PULSE SENSOR_MODE_PERCENT SENSOR_MODE_CELSIUS SENSOR_MODE_FAHRENHEIT SENSOR_MODE_ROTATION SENSOR_TYPE_TOUCH SENSOR_TYPE_TEMPERATURE SENSOR_TYPE_LIGHT SENSOR_TYPE_ROTATION Outputs OUT_A OUT_B OUT_C Output modes OUT_FLOAT OUT_OFF OUT_ON Output directions OUT_REV OUT_TOGGLE OUT_FWD Motors in reverse Motors change direction Motors forward 0 0x40 0x80 Let motors coast Stop motors Run motors 0 hex 0x40 hex 0x80 Select motor A Select motor B Select motor C 1 << 0 1 << 1 1 << 2 Raw value from sensor (0 to 1023) Return Boolean (0 or 1) value Count number of rising/ falling edges Count number of pulses Show value as percentage Temperature sensor Celsius reading Temperature sensor Fahrenheit reading Rotation encoder Pushbutton switch Temperature sensor Powered light detector Rotation encoder hex 0x00 hex 0x20 hex 0x40 hex 0x60 hex 0x80 hex 0xa0 hex 0xc0 hex 0xe0 1 2 3 4 Input 1 Input 2 Input 3 0 1 2
182 PROGRAMMING THE LEGO MINDSTORMS RCX
TABLE 14.1
NQC STANDARD CONSTANTS (Continued) FUNCTION EQUIVALENT VALUE
CONSTANT NAME
Output power levels OUT_LOW OUT_HALF OUT_FULL Sounds for PlaySound SOUND_CLICK SOUND_DOUBLE_BEEP SOUND_DOWN SOUND_UP SOUND_LOW_BEEP Short beep Two beeps Tone scale down Tone scale up Error beep 0 1 2 3 4 Motors at low speed Motors at medium speed Motors at full speed 0 3 7
each { character there must always be a } character, indicating the end of the block. You will use blocks in if, while, and other statements. The one thing you need to remember about blocks and the brace characters that define them, is this: always make sure you have a close brace for every open brace. The next two lines of the program are as follows:
SetPower(MOTOR, 7); SetDirection (MOTOR, OUT_REV);
The SetPower statement sets the power to the motors. The 7 means full power; use 1 for low power or other values in between. SetDirection sets the direction of the outputs, in this case reverse. This will make the robot move toward the light.
SetSensorType(LIGHT, SENSOR_TYPE_LIGHT);
A single light sensor, connected to input 1, is used for the robot. The SetSensorType statement sets the input specified here as LIGHT to accept a powered light.
while(true) { if(LIGHT > 60) On(MOTOR); else Off(MOTOR); }
The main body of the program is a while loop, which thanks to the true expression repeats the program until you depress the Run button on the RCX a second time or turn the RCX off. The important part of the program is the if statement, which reads (in human terms):
Copyright © OnBarcode.com . All rights reserved.