Program your Lego NXT robot in a Scratch-like language
Electric Guitar
When we decided to build the NXT electric guitar project [4], we found that programming in the native Lego software was very complex, with a difficulty rating of 4/4. Doing the same project in Enchanting, however, turned out to be quite easy. Because we were short some Lego pieces called for in the original project, we made a simpler guitar (Figure 5). (Step-by-step building directions to make the more complex guitar are available online.)
To begin the programming, you need to configure the ultrasonic sensor by clicking the Sensing button, then selecting the Configure Sensors button. Next, drag the ultrasonic sensor
block to the port you are using (Figure 6).
For our guitar project, we used an octave (eight notes), and each note was 3cm on the guitar neck. Our code had eight if
blocks in which we defined the distance from the ultrasonic sensor to the neck slider and the note to play in that range (Figure 7). When you click on the note in the play note
block, a little keyboard pops up to show you the key.
In the final code (Figure 8), a forever
block is used to keep the program running. An if
block is used to determine whether you have pushed the Enter key; if so, a note is played based on the distance of the slider bar from the ultrasonic sensor.
Some future project ideas could include:
- Use the left or right buttons to change the instrument.
- Use the left or right buttons to change the beat length.
- Create some tunes that people could try to play back.
Reloading Lego Firmware
If you ever need to reload the original Lego NXT firmware, the Lego software has an Update NXT Firmware option (Figure 9). You can find an Enchanting tutorial online [5].
Infos
- Enchanting examples: http://enchanting.robotclub.ab.ca/Enchanting
- Enchanting on Launchpad: https://launchpad.net/enchanting
- NXT example projects: http://www.nxtprograms.com/index2.html
- Guitar instructions: http://www.nxtprograms.com/guitar/index.html
- Enchanting tutorial: https://cloud.github.com/downloads/monofonik/cellular/Robotics-with-Enchanting-1.1.pdf
« Previous 1 2 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)