Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Examples: Data Humbs, Math Blocks, Logic Blocks, Variables, Etc

 

Example 1

Logic Block, Data Wires and Hubs

Example 2

Math Block, Data Wires and Hubs

Example 3

Logic Block, Data Wires and Hubs

Example 4

Variable, Logic Blocks, Data Wries and Hubs

 

Example 1: Light Sensor, Logic, Motor

 

 

   The yellow wire carries the light intensity reading (numeric data)  from the sensor block to the logic block.

 

   The second wire (green) carries a logical signal from the logic block to the move block


 

 

Example 2: Math Block

 

   The yellow wire carries the counter output of loop block

   This generates a tone of gradually increasing pitch

 

Example 3: Using a Logical Signal to End a Loop

   Light sensor on port 3 sends signal to logic block

   Light sensor on port 4 sends signal to logic block

   When both are true, the robot stops bleeping, exits the loop, and says Thank You

 

Example 4

Data Wires, Hubs, and Variables

Using Variables with Switches

Also includes Sound Sensor, Data Hubs, Logic Operators, Display, Loop Block

 

 

The Program

 

   First,  define a variable called Maximum, to hold the highest sound level the robot senses.

 

   Then the program enters a loop (technically, a "loop until" type structure - it checks the exit condition at the end, just like the graphics imply).

 

   Inside the loop, the current value value from the sound sensor (hooked to port #2 - the block shows you this right on the icon) is obtained.

 

   This value is wired into a Compare block, that compares it to the current value of the variable.

 

   The result of that comparision is a logical condition: True or False.

 

   That result is then wired into a Switch block, allowing two different courses of action depending on what logical value the Compare block wired out.

 

   Finally, the loop checks to see if the "left arrow" button on the front panel of the NXT is pressed, and if it is it will exit the loop.

Commentary on the Color Scheme for Wires

 

   Notice how wires are different colors. That way you can keep straight the different types of information (numbers, logical, text).

 

   Wires can branch and connect one output plug to multiple input plugs, and the editor keeps you from wiring the wrong type of data in.

 

   Try to connect a number to a logical. The editor won't let you, but instead display a "broken" wire).

 

Notes

 

  Variables in NXT-G are all global 

  All variable blocks with the same name always references the same variable, in any sequence and any My Block in the program.