Main Page | Class Hierarchy | 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
00001 // 00002 // The contents of this file are subject to the Mozilla Public License 00003 // Version 1.0 (the "License"); you may not use this file except in 00004 // compliance with the License. You may obtain a copy of the License 00005 // at http://www.mozilla.org/MPL/ 00006 // 00007 // Software distributed under the License is distributed on an "AS IS" 00008 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00009 // the License for the specific language governing rights and 00010 // limitations under the License. 00011 // 00012 // This software was developed as part of the legOS project. 00013 // 00014 // Contributor: Pat Welch (legOS@mousebrains.com) 00015 00016 #include <config.h> 00017 #if defined(CONF_DSENSOR) 00018 00019 #include <c++/Battery.H> 00020 #include <conio.h> 00021 #include <unistd.h> 00022 #include <tm.h> 00023 00024 // This program reads the sensor and displays the hex value on 00026 00027 int 00028 main(int argc, 00029 char **argv) 00030 { 00031 Battery b; 00032 00033 while (!shutdown_requested()) { 00034 cputs("batt"); 00035 sleep(1); 00036 lcd_int(b.get()); 00037 sleep(1); 00038 } 00039 return 0; 00040 } 00041 00042 #else 00043 #warning batt.C requires CONF_DSENSOR 00044 #warning batt demo will do nothing 00045 int main(int argc, char *argv[]) { 00046 return 0; 00047 } 00048 #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
00001 // 00002 // The contents of this file are subject to the Mozilla Public License 00003 // Version 1.0 (the "License"); you may not use this file except in 00004 // compliance with the License. You may obtain a copy of the License 00005 // at http://www.mozilla.org/MPL/ 00006 // 00007 // Software distributed under the License is distributed on an "AS IS" 00008 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00009 // the License for the specific language governing rights and 00010 // limitations under the License. 00011 // 00012 // This software was developed as part of the legOS project. 00013 // 00014 // Contributor: Pat Welch (legOS@mousebrains.com) 00015 00016 // This program beeps once a second 00017 00018 #include <config.h> 00019 #if defined(CONF_DMOTOR) 00020 00021 #include <unistd.h> // for the sleep() func. 00022 #include <tm.h> // for the shutdown_requested() func. 00023 00024 #include <c++/Lamp.H> 00025 00026 int 00027 main(int argc, 00028 char **argv) 00029 { 00030 Lamp myLite(Lamp::B); 00031 int power = 0; 00032 00033 myLite.on(); 00034 while (power < 255 && !shutdown_requested()) { 00035 myLite.brightness(power); 00036 sleep(1); 00037 power += (256/8); 00038 } 00039 myLite.off(); 00040 return 0; 00041 } 00042 #else // CONF_DMOTOR 00043 #warning lampTest.C requires CONF_DMOTOR 00044 #warning lamp demo will do nothing 00045 int 00046 main(int argc, 00047 char **argv) 00048 { 00049 return 0; 00050 } 00051 #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
00001 // 00002 // The contents of this file are subject to the Mozilla Public License 00003 // Version 1.0 (the "License"); you may not use this file except in 00004 // compliance with the License. You may obtain a copy of the License 00005 // at http://www.mozilla.org/MPL/ 00006 // 00007 // Software distributed under the License is distributed on an "AS IS" 00008 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00009 // the License for the specific language governing rights and 00010 // limitations under the License. 00011 // 00012 // This software was developed as part of the legOS project. 00013 // 00014 // Contributor: Pat Welch (legOS@mousebrains.com) 00015 00016 // This program beeps once a second 00017 00018 #include <config.h> 00019 #if defined(CONF_DSOUND) 00020 00021 #include <c++/Sound.H> 00022 #include <conio.h> 00023 #include <unistd.h> 00024 #include <tm.h> 00025 00026 int 00027 main(int argc, 00028 char **argv) 00029 { 00030 while (!shutdown_requested()) { 00031 Sound::beep(); 00032 cputs ("Beep"); 00033 sleep(1); 00034 cls(); 00035 } 00036 cls(); 00037 00038 return 0; 00039 } 00040 #else // CONF_DSOUND 00041 #warning sound.C requires CONF_DSOUND 00042 #warning sound demo will do nothing 00043 int 00044 main(int argc, 00045 char **argv) 00046 { 00047 return 0; 00048 } 00049 #endif // CONF_DSOUND

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

Generated on Thu Jul 29 08:55:51 2004 for brickOS C++ by doxygen 1.3.7