These examples (ZIP) demonstrate some ways of working with sounds, displays, and delays in NXT-G.
Controlling the Display
- This program uses two touch sensors combined with two Switches – all in an infinite loop – to display a number on the screen. Port 1 adds 1 and Port 2 adds 100. The “adder” variable is set to zero at the beginning of this program.
- In this code, sound frequencies are played corresponding to changing light values. Light sensor readings, which fall between 0-100, are placed in a variable and multiplied by the constant 8. The value of that variable, which now falls between 0-800, becomes the frequency in Hz of the sound played. The frequency is also displayed on the NXT.
- This program says “Hello.”
Play the Scale
- The NXT can also be used to play music. By placing notes manually custom songs can be created.
Wait for Push
- This code illustrates the Wait-for-Push command. When a touch sensor on Port 1 is pressed, Motor A will stop.
Wait for Random
- This code creates a wait for loop that will wait for a random amount of time. The code uses the random number generator and a loop that waits for the timer to equal the generated value. The random number is set between 500 and 5000, which causes the loop to wait for 500 and 5000 milliseconds. Code by Brian Davis.
- NXT-G examples (ZIP)
The following two tabs change content below.
The Tufts Center for Engineering Education and Outreach (CEEO) in Boston, Massachusetts, is dedicated to improving engineering education in the classroom, from Kindergarten to college. The Center houses faculty, staff, and graduate students from engineering disciplines and the education department.