EasyManuals Logo

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #153 background image
.EndIf
' …
.CloseComm
End With
End Sub
Once you've mastered If, the While loop is easy. Like If, it compares two values using an operator. The body of the While (until an EndWhile) is executed until the comparison is false. The
body of the following loop, for example, would be executed as long as the value of input 3 was less than 100:
While SENSOR_VALUE, SENSOR_3, LESS, CONSTANT, 100
' Loop body
EndWhile
Page 168
Other Nuggets
Spirit.ocx offers some interesting capabilities that go beyond even NQC. One of these is the ability to turn off the RCX, using PBTurnOff. Interestingly, this function can be executed either
immediately or inside a program. The following Visual Basic code defines an RCX program that turns itself off:
Sub TurnOffProgram()
With DummySpiritForm.Spirit1
.InitComm
.SelectPrgm 2
.BeginOfTask 0
.PBTurnOff
.EndOfTask
Pause 1
.CloseComm
End With
End Sub
By itself, of course, it's a pretty silly program. You can imagine how it might be useful, though: shouldn't your robot turn itself off when it's accomplished its mission, to conserve battery power?
You can also use Spirit.ocx to query the RCX for the current battery charge. The PBBattery function returns the current battery voltage in milliVolts (mV). For fresh batteries, you should get a
reading of 9000. The following example shows how you can retrieve and display the current battery power level:
Sub ShowBattery()
With DummySpiritForm.Spirit1
.InitComm
battery = .PBBattery()
.CloseComm
MsgBox (battery)
End With
End Sub
Retrieving the Datalog
Back in Chapter 4, I described the datalog, a special set of data in the RCX that your programs can use. It's easy to create a datalog and add values to it in NQC, but how to you get that data back?
Although you can retrieve the datalog using a tool like nqc or RCX Command Center, it may not be in exactly the format you'd like. In this section I'll show you how to write a program in Visual
Basic to extract the datalog from the RCX. You can modify this program to suit your needs.
The main part of the program is a subroutine, SaveDatalog. It opens up communications with the RCX, extracts the datalog values, and writes them into a file of comma-separated values. It's
all pretty straightforward, except that the RCX will

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
Product LineLEGO MINDSTORMS
CategoryToy
Age Range10+
Batteries RequiredYes
Memory64 MB RAM, 16 MB Flash
ConnectivityBluetooth, USB
SensorsTouch, Color, Gyro
Battery TypeAA
Interactive FeaturesProgrammable, Remote Control
App CompatibilityiOS, Android
ProcessorARM9
Pieces Count601
Battery Count6
App NameLEGO MINDSTORMS EV3 Programmer App

Related product manuals