Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Example Programs in C++

Ex1: display battery voltage
a simple demostration of reading the battery and writing to the LCD
demo/batt.C
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License
// at http://www.mozilla.org/MPL/
// 
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// This software was developed as part of the legOS project.
//
// Contributor: Pat Welch (legOS@mousebrains.com)

#include <config.h>
#if defined(CONF_DSENSOR)

#include <c++/Battery.H>
#include <conio.h>
#include <unistd.h>
#include <tm.h>

// This program reads the sensor and displays the hex value on

int 
main(int argc, 
     char **argv) 
{
  Battery b;

  while (!shutdown_requested()) {
    cputs("batt");
    sleep(1);
    lcd_int(b.get());
    sleep(1);
  }
  return 0;
}

#else
#warning batt.C requires CONF_DSENSOR
#warning batt demo will do nothing
int main(int argc, char *argv[]) {
  return 0;
}
#endif // CONF_DSENSOR

Ex2: emitting light (Using Lamp from the Ultimate Accessory Set)
a demostration of the controlling the Lamp
demo/lampTest.C
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License
// at http://www.mozilla.org/MPL/
// 
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// This software was developed as part of the legOS project.
//
// Contributor: Pat Welch (legOS@mousebrains.com)

// This program beeps once a second

#include <config.h>
#if defined(CONF_DMOTOR)

#include <unistd.h>             // for the sleep() func.
#include <tm.h>                 // for the shutdown_requested() func.

#include <c++/Lamp.H>

int 
main(int argc, 
     char **argv) 
{
  Lamp myLite(Lamp::B);
  int power = 0;
  
  myLite.on();
  while (power < 255 && !shutdown_requested()) {
        myLite.brightness(power);
        sleep(1);
        power += (256/8);
  }
  myLite.off();
  return 0;
}
#else // CONF_DMOTOR
#warning lampTest.C requires CONF_DMOTOR
#warning lamp demo will do nothing
int 
main(int argc, 
     char **argv) 
{
  return 0;
}
#endif // CONF_DMOTOR

Ex3: generating sounds
a simple demostration of the RCX playing music
demo/sound.C
//
// The contents of this file are subject to the Mozilla Public License
// Version 1.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License
// at http://www.mozilla.org/MPL/
// 
// Software distributed under the License is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
// the License for the specific language governing rights and
// limitations under the License.
//
// This software was developed as part of the legOS project.
//
// Contributor: Pat Welch (legOS@mousebrains.com)

// This program beeps once a second

#include <config.h>
#if defined(CONF_DSOUND)

#include <c++/Sound.H>
#include <conio.h>
#include <unistd.h>
#include <tm.h>

int 
main(int argc, 
     char **argv) 
{
  while (!shutdown_requested()) {
    Sound::beep();
    cputs ("Beep");
    sleep(1);
    cls();
  }
  cls();
  
  return 0;
}
#else // CONF_DSOUND
#warning sound.C requires CONF_DSOUND
#warning sound demo will do nothing
int
main(int argc,
     char **argv)
{
  return 0;
}
#endif // CONF_DSOUND

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2002 by the authors.

Generated on Mon Feb 16 21:02:35 2004 for brickOS Kernel Developer by doxygen 1.3.5