root/trunk/publishing/MATLABCentral/Example_1_PlayTone.m @ 701

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://www.mindstorms.rwth-aachen.de
8
9% Close previous handles (if existing)
10COM_CloseNXT all
11% Prepare workspace by cleaning all old settings to be on the safe side.
12clear all
13close 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)
19handle = COM_OpenNXT();
20
21% Play tone with frequency 800Hz and duration of 500ms.
22NXT_PlayTone(800,500, handle);
23
24% Get current battery level.
25voltage = NXT_GetBatteryLevel(handle)
26
27% Close NXT connection.
28COM_CloseNXT(handle);
Note: See TracBrowser for help on using the browser.