|
Revision 701, 1.0 KB
(checked in by behrens, 4 years ago)
|
- update MATLAB Central documents
|
| Line | |
|---|
| 1 | %% Example 1: Play Tone and Get Battery Level |
|---|
| 2 | % Example to play a specific tone with the NXT Brick and retrieve the current battery level: |
|---|
| 3 | % |
|---|
| 4 | % Signature |
|---|
| 5 | % Author: Linus Atorf, Alexander Behrens |
|---|
| 6 | % Date: 2009/07/17 |
|---|
| 7 | % RWTH - Mindstorms NXT Toolbox: http: |
|---|
| 8 | |
|---|
| 9 | % Close previous handles (if existing) |
|---|
| 10 | COM_CloseNXT all |
|---|
| 11 | % Prepare workspace by cleaning all old settings to be on the safe side. |
|---|
| 12 | clear all |
|---|
| 13 | close all |
|---|
| 14 | |
|---|
| 15 | % Open new NXT connection |
|---|
| 16 | % - Tries to open a connection via USB. The first NXT device that is found will be used. |
|---|
| 17 | % - Device drivers (Fantom on Windows, libusb on Linux) have to be already installed for USB to work. |
|---|
| 18 | % - For using Bluetooth a previous configuration file has to be generated COM_MakeBTConfigFile) |
|---|
| 19 | handle = COM_OpenNXT(); |
|---|
| 20 | |
|---|
| 21 | % Play tone with frequency 800Hz and duration of 500ms. |
|---|
| 22 | NXT_PlayTone(800,500, handle); |
|---|
| 23 | |
|---|
| 24 | % Get current battery level. |
|---|
| 25 | voltage = NXT_GetBatteryLevel(handle) |
|---|
| 26 | |
|---|
| 27 | % Close NXT connection. |
|---|
| 28 | COM_CloseNXT(handle); |
|---|