Full Code of atduskgreg/rad for AI

master 353a9f4040fb cached
114 files
384.7 KB
114.6k tokens
599 symbols
1 requests
Download .txt
Showing preview only (414K chars total). Download the full file or copy to clipboard to get everything.
Repository: atduskgreg/rad
Branch: master
Commit: 353a9f4040fb
Files: 114
Total size: 384.7 KB

Directory structure:
gitextract_7rauuwcn/

├── .gitignore
├── History.txt
├── License.txt
├── Manifest.txt
├── README.markdown
├── Rakefile
├── bin/
│   └── rad
├── lib/
│   ├── examples/
│   │   ├── add_hysteresis.rb
│   │   ├── basic_blink.rb
│   │   ├── blink_m_address_assignment.rb
│   │   ├── blink_m_hello.rb
│   │   ├── blink_m_multi.rb
│   │   ├── blink_with_serial.rb
│   │   ├── configure_pa_lcd_boot.rb
│   │   ├── debounce_methods.rb
│   │   ├── external_variable_fu.rb
│   │   ├── external_variables.rb
│   │   ├── first_sound.rb
│   │   ├── frequency_generator.rb
│   │   ├── hello_array.rb
│   │   ├── hello_array2.rb
│   │   ├── hello_array_eeprom.rb
│   │   ├── hello_clock.rb
│   │   ├── hello_eeprom.rb
│   │   ├── hello_eeprom_lcdpa.rb
│   │   ├── hello_format_print.rb
│   │   ├── hello_lcd_charset.rb
│   │   ├── hello_pa_lcd.rb
│   │   ├── hello_servos.rb
│   │   ├── hello_spectra_sound.rb
│   │   ├── hello_world.rb
│   │   ├── hello_xbee.rb
│   │   ├── hysteresis_duel.rb
│   │   ├── i2c_with_clock_chip.rb
│   │   ├── midi_beat_box.rb
│   │   ├── midi_scales.rb
│   │   ├── motor_knob.rb
│   │   ├── servo_buttons.rb
│   │   ├── servo_calibrate_continuous.rb
│   │   ├── servo_throttle.rb
│   │   ├── software_serial.rb
│   │   ├── sparkfun_lcd.rb
│   │   ├── spectra_soft_pot.rb
│   │   ├── times_method.rb
│   │   ├── toggle.rb
│   │   ├── twitter.rb
│   │   └── two_wire.rb
│   ├── libraries/
│   │   └── Wire/
│   │       └── utility/
│   │           ├── twi.c
│   │           └── twi.h
│   ├── plugins/
│   │   ├── bitwise_ops.rb
│   │   ├── blink.rb
│   │   ├── blink_m.rb
│   │   ├── debounce.rb
│   │   ├── debug_output_to_lcd.rb
│   │   ├── hysteresis.rb
│   │   ├── input_output_state.rb
│   │   ├── lcd_padding.rb
│   │   ├── mem_test.rb
│   │   ├── midi.rb
│   │   ├── parallax_ping.rb
│   │   ├── servo_pulse.rb
│   │   ├── servo_setup.rb
│   │   ├── smoother.rb
│   │   ├── spark_fun_serial_lcd.rb
│   │   ├── spectra_symbol.rb
│   │   └── twitter_connect.rb
│   ├── rad/
│   │   ├── README.rdoc
│   │   ├── antiquated_todo.txt
│   │   ├── arduino_plugin.rb
│   │   ├── arduino_sketch.rb
│   │   ├── darwin_installer.rb
│   │   ├── generators/
│   │   │   └── makefile/
│   │   │       ├── makefile.erb
│   │   │       └── makefile.rb
│   │   ├── hardware_library.rb
│   │   ├── init.rb
│   │   ├── linux_installer.rb
│   │   ├── progressbar.rb
│   │   ├── rad_processor.rb
│   │   ├── rad_rewriter.rb
│   │   ├── rad_type_checker.rb
│   │   ├── sim/
│   │   │   └── arduino_sketch.rb
│   │   ├── sketch_compiler.rb
│   │   ├── tasks/
│   │   │   ├── build_and_make.rake
│   │   │   └── rad.rb
│   │   ├── todo.txt
│   │   ├── variable_processing.rb
│   │   └── version.rb
│   └── rad.rb
├── rad.gemspec
├── scripts/
│   └── txt2html
├── setup.rb
├── spec/
│   ├── examples/
│   │   ├── hello_world.rb
│   │   └── serial_motor.rb
│   ├── models/
│   │   ├── arduino_sketch_spec.rb
│   │   ├── sketch_compiler_spec.rb
│   │   └── spec_helper.rb
│   ├── sim/
│   │   └── hello_world_spec.rb
│   └── spec.opts
├── test/
│   ├── hello_world_test/
│   │   ├── Makefile
│   │   └── hello_world.cpp
│   ├── test_array_processing.rb
│   ├── test_plugin_loading.rb
│   ├── test_translation_post_processing.rb
│   └── test_variable_processing.rb
└── website/
    ├── examples/
    │   ├── assembler_test.rb.html
    │   ├── gps_reader.rb.html
    │   ├── hello_world.rb.html
    │   └── serial_motor.rb.html
    ├── index.html
    ├── index.txt
    ├── javascripts/
    │   └── rounded_corners_lite.inc.js
    ├── stylesheets/
    │   ├── code.css
    │   └── screen.css
    └── template.rhtml

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
.DS_Store
bin/.DS_Store
lib/.DS_Store
lib/libraries/.DS_Store
lib/rad/.DS_Store
lib/libraries/*/*.*

================================================
FILE: History.txt
================================================
== 0.3.0 2008-09-22
* Pushing to rubyforge.. 
	- added rad install arduino
	- added rad test arduino

== 0.2.5 2008-07-21
* 1ish large post Bastille Day update:
	- added i2c capability
	- added actual Wire library until workaround for os_x file caching is found
	- added DS1307 and OneWire libraries
	- added cool instance variable style global variables
	- added array and define methods
	- added def setup method, which added to setup 
	- added numerous examples

== 0.2.4 2008-07-12
* 1ish large update:
	- added incredibly primitive tests 
	- added 11 sketch examples which are compiled or compiled/uploaded
		- use rake test:compile or rake test:upload
		- can also use the following to run an example (make:compile also works)
		- make:upload sketch=examples/hello_servos

== 0.2.3 2008-07-10
* Manyish updates:
	- updated servo library to support position parameter
	- plus:
	- addition of plugins
	- latest and greatest lcd libraries for pa and sf
	- multiple methods 
	- addition of rad_process and rad_rewrite methods methods
	- options for :device => servo, button, lcd, 
	- and many more

== 0.2.2 2008-04-27
* 2ish updates:
	- updated makefile template and cli to expect arduino-0011
	- applied David Michael's patch for longs
	
== 0.2.1 2008-04-02
* 6ish updates:
	- applied Brian Riley's SWSerLCDpa patch
	- experimental libraries system in vendor/libraries
	- fixed require 'yaml' bug in makefile.rb
	- enhancements to the rad command: can set project config.
	- added first significant documentation 
	- added examples directory to the website

== 0.2.0 2008-03-15
* 8ish updates, some major:
	* fixed regular serial support
	* class method for writing functions in assembler
	* applied Scott Windsor's patch for software serial support
	* added support for HIGH/LOW/ON/OFF constants
	* add an option for skipping the reset prompt on rake make:upload
	* changed default arduino location to be more realistic
	* put screencasts #1 and #2 on rad.rubyforge.org
	* put google analytics on rad.rubyforge.org
	
== 0.1.1 2007-10-29
* 2 major fixes:
  * explicitly specify path to arduino avr tools (this was broken on systems that didn't have the avr toolchain installed, oops)
  * add explicit path to avrdude.conf in the upload make target

== 0.1.0 2007-10-28
* 4ish major updates:
  * Arduino interop has been updated, and consequently now requires Arduino 0010:
    * new Makefile imported, with new configuration items (see below)
    * main() function added to C++ output
    * make:upload rake task has been updated
  * C++ generation has been changed to produce a more readable output
  * configuration file changes:
    * hardware
      * fixed typo in serial_port key
      * added mcu key to specify atmega8/atmega168.  Defaults to atmega168
      * changed serial_port to /dev/tty.usbserial*, which will pick the first device that matches that blob
    * software
      * updated arduino_root for 0010
* 2 major enhancement:
  * gem should now correctly install RubyToC
  * can now enable internal pull-up resistors on input pins by passing the :pullup => true parameter to input_pin
* 2 minor enhancements:
  * cleanups in makefile.rb
  * serial_print_str method added; can now send strings over the serial port

== 0.0.4 2007-07-24

* 1 major enhancement:
  * serial_begin class method
  
== 0.0.3 2007-07-23

* 1 major enhancement:
  * bug fix in blink helper method
  
== 0.0.2 2007-07-23

* 1 major enhancement:
  * blink helper method
  
== 0.0.1 2007-07-22

* 1 major enhancement:
  * Initial release
  * most features of the Arduino software library functional
  * experimental implementation of the serial interface
  * complete rake-based build, compile, and upload cycle




================================================
FILE: License.txt
================================================

                    GNU GENERAL PUBLIC LICENSE
                       Version 2, June 1991

Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

                            Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

                    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation.  If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

                            NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.





================================================
FILE: Manifest.txt
================================================
History.txt
License.txt
Manifest.txt
README.rdoc
Rakefile
bin/rad
lib/examples/add_hysteresis.rb
lib/examples/basic_blink.rb
lib/examples/blink_m_address_assignment.rb
lib/examples/blink_m_hello.rb
lib/examples/blink_m_multi.rb
lib/examples/blink_with_serial.rb
lib/examples/configure_pa_lcd_boot.rb
lib/examples/debounce_methods.rb
lib/examples/external_variable_fu.rb
lib/examples/external_variables.rb
lib/examples/first_sound.rb
lib/examples/frequency_generator.rb
lib/examples/hello_array.rb
lib/examples/hello_array2.rb
lib/examples/hello_array_eeprom.rb
lib/examples/hello_clock.rb
lib/examples/hello_eeprom.rb
lib/examples/hello_eeprom_lcdpa.rb
lib/examples/hello_format_print.rb
lib/examples/hello_lcd_charset.rb
lib/examples/hello_pa_lcd.rb
lib/examples/hello_servos.rb
lib/examples/hello_spectra_sound.rb
lib/examples/hello_world.rb
lib/examples/hello_xbee.rb
lib/examples/hysteresis_duel.rb
lib/examples/i2c_with_clock_chip.rb
lib/examples/midi_beat_box.rb
lib/examples/midi_scales.rb
lib/examples/motor_knob.rb
lib/examples/servo_buttons.rb
lib/examples/servo_calibrate_continuous.rb
lib/examples/servo_throttle.rb
lib/examples/software_serial.rb
lib/examples/sparkfun_lcd.rb
lib/examples/spectra_soft_pot.rb
lib/examples/times_method.rb
lib/examples/toggle.rb
lib/examples/twitter.rb
lib/examples/two_wire.rb
lib/libraries/AFSoftSerial/AFSoftSerial.cpp
lib/libraries/AFSoftSerial/AFSoftSerial.h
lib/libraries/AFSoftSerial/keywords.txt
lib/libraries/AF_XPort/AF_XPort.cpp
lib/libraries/AF_XPort/AF_XPort.h
lib/libraries/DS1307/DS1307.cpp
lib/libraries/DS1307/DS1307.h
lib/libraries/DS1307/keywords.txt
lib/libraries/FrequencyTimer2/FrequencyTimer2.cpp
lib/libraries/FrequencyTimer2/FrequencyTimer2.h
lib/libraries/FrequencyTimer2/keywords.txt
lib/libraries/I2CEEPROM/I2CEEPROM.cpp
lib/libraries/I2CEEPROM/I2CEEPROM.h
lib/libraries/I2CEEPROM/keywords.txt
lib/libraries/LoopTimer/LoopTimer.cpp
lib/libraries/LoopTimer/LoopTimer.h
lib/libraries/LoopTimer/keywords.txt
lib/libraries/OneWire/OneWire.cpp
lib/libraries/OneWire/OneWire.h
lib/libraries/OneWire/keywords.txt
lib/libraries/OneWire/readme.txt
lib/libraries/SWSerLCDpa/SWSerLCDpa.cpp
lib/libraries/SWSerLCDpa/SWSerLCDpa.h
lib/libraries/SWSerLCDsf/SWSerLCDsf.cpp
lib/libraries/SWSerLCDsf/SWSerLCDsf.h
lib/libraries/Servo/Servo.cpp
lib/libraries/Servo/Servo.h
lib/libraries/Stepper/Stepper.cpp
lib/libraries/Stepper/Stepper.h
lib/libraries/Stepper/keywords.txt
lib/libraries/Wire/Wire.cpp
lib/libraries/Wire/Wire.h
lib/libraries/Wire/keywords.txt
lib/libraries/Wire/twi.h
lib/libraries/Wire/utility/twi.c
lib/libraries/Wire/utility/twi.h
lib/plugins/bitwise_ops.rb
lib/plugins/blink.rb
lib/plugins/blink_m.rb
lib/plugins/debounce.rb
lib/plugins/debug_output_to_lcd.rb
lib/plugins/hysteresis.rb
lib/plugins/input_output_state.rb
lib/plugins/lcd_padding.rb
lib/plugins/mem_test.rb
lib/plugins/midi.rb
lib/plugins/parallax_ping.rb
lib/plugins/servo_pulse.rb
lib/plugins/servo_setup.rb
lib/plugins/smoother.rb
lib/plugins/spark_fun_serial_lcd.rb
lib/plugins/spectra_symbol.rb
lib/plugins/twitter_connect.rb
lib/rad.rb
lib/rad/README.rdoc
lib/rad/arduino_plugin.rb
lib/rad/arduino_sketch.rb
lib/rad/darwin_installer.rb
lib/rad/generators/makefile/makefile.erb
lib/rad/generators/makefile/makefile.rb
lib/rad/hardware_library.rb
lib/rad/init.rb
lib/rad/linux_installer.rb
lib/rad/progressbar.rb
lib/rad/rad_processor.rb
lib/rad/rad_rewriter.rb
lib/rad/rad_type_checker.rb
lib/rad/sim/arduino_sketch.rb
lib/rad/sketch_compiler.rb
lib/rad/tasks/build_and_make.rake
lib/rad/tasks/rad.rb
lib/rad/todo.txt
lib/rad/variable_processing.rb
lib/rad/version.rb
scripts/txt2html
setup.rb
spec/examples/hello_world.rb
spec/examples/serial_motor.rb
spec/models/arduino_sketch_spec.rb
spec/models/sketch_compiler_spec.rb
spec/models/spec_helper.rb
spec/sim/hello_world_spec.rb
spec/spec.opts
test/hello_world_test/Makefile
test/hello_world_test/hello_world.cpp
test/test_array_processing.rb
test/test_plugin_loading.rb
test/test_translation_post_processing.rb
test/test_variable_processing.rb
website/index.html
website/index.txt
website/javascripts/rounded_corners_lite.inc.js
website/stylesheets/screen.css
website/template.rhtml
website/examples/assembler_test.rb.html
website/examples/gps_reader.rb.html
website/examples/hello_world.rb.html
website/examples/serial_motor.rb.html

================================================
FILE: README.markdown
================================================
# Welcome to RAD (Ruby Arduino Development)

RAD is a framework for programming the Arduino physcial computing platform using Ruby. RAD converts Ruby scripts written using a set of Rails-like conventions and helpers into C source code which can be compiled and run on the Arduino microcontroller. It also provides a set of Rake tasks for automating the compilation and upload process.

For a full introduction see http://rad.rubyforge.org

## Documentation

The main documentation is here: ArduinoSketch.

See also the Arduino Software reference: http://www.arduino.cc/en/Reference/HomePage

## Examples

See the examples directory for lots of examples of RAD in action: 
http://github.com/atduskgreg/rad/tree/master/lib/examples

The atduskgreg/rad wiki also contains a growing library of examples and hardware tutorials:
http://github.com/atduskgreg/rad/wikis

## Getting Started

To install the gem:

    $ gem install rad

Run the rad command to create a new project:

    $ rad my_project

Write a sketch that will blink a single LED every 500ms:

```ruby
class MyProject < ArduinoSketch
  output_pin 13, :as => led
  def loop
    blink led, 500
  end
end
```

Attach your Arduino and use rake to complile and upload your sketch:

    $ rake make:upload

##Installing the Arduino Software

Installing RAD and the Arduino software on Linux can be a little more difficult than on OS X. Thankfully, the RAD command line tool can help. Run:

    $ rad install arduino

And RAD will do its best to get the Arduino software installed on your system.

#Get Involved

##Note on Patches/Pull Requests

* Fork the project.
* Make your feature addition or bug fix on a new topic branch
* Add specs and cukes for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Issue a pull request.

##Cheers?  Jeers?  Questions?  Comments?  

Contact Greg Borenstein - greg [dot] borenstein [at] gmail [dot] com

Matthew Williams - matthew [dot] williams [at] gmail [dot] com

Also, please don't hesitate to submit issues!

================================================
FILE: Rakefile
================================================
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/testtask'
require 'rake/packagetask'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/contrib/rubyforgepublisher'
require 'fileutils'
require 'hoe'

RAD_ROOT = File.expand_path(File.dirname(__FILE__))

begin
  require 'spec/rake/spectask'
rescue LoadError
  puts 'To use rspec for testing you must install rspec gem:'
  puts '$ sudo gem install rspec'
  exit
end

include FileUtils
require File.join(File.dirname(__FILE__), 'lib', 'rad', 'version')

BIN = "rad"
AUTHOR = 'Greg Borenstein'  # can also be an array of Authors
EMAIL = "greg@mfdz.com"
DESCRIPTION = "A framework for programming the Arduino physcial computing platform using Ruby. RAD converts Ruby scripts written using a set of Rails-like conventions and helpers into C source code which can be compiled and run on the Arduino microcontroller."
GEM_NAME = 'rad' # what ppl will type to install your gem

@config_file = "~/.rubyforge/user-config.yml"
@config = nil
def rubyforge_username
  unless @config
    begin
      @config = YAML.load(File.read(File.expand_path(@config_file)))
    rescue
      puts <<-EOS
ERROR: No rubyforge config file found: #{@config_file}"
Run 'rubyforge setup' to prepare your env for access to Rubyforge
 - See http://newgem.rubyforge.org/rubyforge.html for more details
      EOS
      exit
    end
  end
  @rubyforge_username ||= @config["username"]
end

RUBYFORGE_PROJECT = 'rad' # The unix name for your project
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"

NAME = "rad"
REV = nil 
# UNCOMMENT IF REQUIRED: 
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
VERS = Rad::VERSION::STRING + (REV ? ".#{REV}" : "")
CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
RDOC_OPTS = ['--quiet', '--title', 'rad documentation',
    "--opname", "index.html",
    "--line-numbers", 
    "--main", "README",
    "--inline-source"]

class Hoe
  def extra_deps 
    @extra_deps.reject { |x| Array(x).first == 'hoe' } 
  end 
end

# Generate all the Rake tasks
# Run 'rake -T' to see list of generated tasks (from gem root directory)
hoe = Hoe.new(GEM_NAME, VERS) do |p|
  p.author = AUTHOR 
  p.description = DESCRIPTION
  p.email = EMAIL
  p.summary = DESCRIPTION
  p.url = HOMEPATH
  p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
  p.test_globs = ["test/**/test_*.rb"]
  p.clean_globs |= CLEAN  #An array of file patterns to delete on clean.
  
  # == Optional
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
  p.extra_deps =  [ ['RubyToC', '>= 1.0.0'] ]
  #p.spec_extras = {}    # A hash of extra values to set in the gemspec.
end

CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
PATH    = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')

desc 'Generate website files'
task :website_generate do
  Dir['website/**/*.txt'].each do |txt|
    sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
  end
end

desc 'Upload website files to rubyforge'
task :website_upload do
  host = "#{rubyforge_username}@rubyforge.org"
  remote_dir = "/var/www/gforge-projects/#{PATH}/"
  local_dir = 'website'
  sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
end

desc 'Generate and upload website files'
task :website => [:website_generate, :website_upload, :publish_docs]

desc 'Release the website and new gem version'
task :deploy => [:check_version, :website, :release] do
  puts "Remember to create SVN tag:"
  puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
    "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
  puts "Suggested comment:"
  puts "Tagging release #{CHANGES}"
end

desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
task :local_deploy => [:website_generate, :install_gem]

task :check_version do
  unless ENV['VERSION']
    puts 'Must pass a VERSION=x.y.z release version'
    exit
  end
  unless ENV['VERSION'] == VERS
    puts "Please update your version.rb to match the release version, currently #{VERS}"
    exit
  end
end

desc "Run the specs under spec/models"
Spec::Rake::SpecTask.new do |t|
  t.spec_opts = ['--options', "spec/spec.opts"]
  t.spec_files = FileList['spec/models/*_spec.rb']
end

desc "Default task is to run specs"
task :default => :spec



================================================
FILE: bin/rad
================================================
#!/usr/bin/env ruby

begin
  require 'rubygems'
rescue LoadError
  # no rubygems to load, so we fail silently
end

require 'optparse'
require 'fileutils'
require 'yaml'
require 'open-uri'
require 'readline'

require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/version.rb"
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/progressbar.rb"
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/linux_installer.rb"
require File.expand_path(File.dirname(__FILE__)) + "/../lib/rad/darwin_installer.rb"

class OptionParser #:nodoc:
    
  def self.parse(args)
    # defaults
    
    options = {"hardware" => {
                "serial_port"      => '/dev/tty.usbserial*', 
                "mcu"              => "atmega168", 
                "physical_reset"   => false
                },
                "software" => {
                  "arduino_root"   => "/Applications/arduino-0012"
                 }
               }
    
    opts = OptionParser.new do |opts|
      
      opts.banner = <<-BANNER
Build a directory for your RAD Project and install RAD in its vendor sub-directory.

Usage: #{File.basename($0)} <sketch_dir_name> <options for config>
      BANNER
      
      opts.on("-p", "--port [SERIAL PORT]", 
              "Path to your serial port", 
              "   (default: #{options['hardware']['serial_port']})") do |port|
              
        options["hardware"]["serial_port"] = port if port
      end
      
       opts.on("-m", "--mcu [PROCESSOR TYPE]", 
              "Type of processor on your board", 
              "   (default: #{options['hardware']['mcu']})") do |port|
              
        options["hardware"]["serial_port"] = port if port
      end
      
      opts.on("-r", "--reset [RESET REQUIRED]", 
              "Require a hardware reset before uploading?",
              "   (default: #{options['hardware']['physical_reset']})") do |no_reset|
        options["hardware"]["physical_reset"] = true unless no_reset
      end
      
      opts.on("-a", "--arduino [ARDUINO DIR]", 
              "Path to your Arduino install",
              "   (default: #{options['software']['arduino_root']})") do |arduino|
        options["software"]["arduino_root"] = arduino if arduino
      end
      
      opts.on("-v", "--version [VERSION]", 
              "RAD version number",
              "   (#{Rad::VERSION::STRING})") do 
        puts Rad::VERSION::STRING
        exit
      end

      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
    end
    
    opts.parse!(args)
    [options, opts]
  end
  
end


# home = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
# begin
#   config = YAML::load open(home + "/.rad")
# rescue
#   config = false
# end
# 


if ARGV[0] == "install"
  
  case RUBY_PLATFORM
  when /linux/
    LinuxInstaller.install!
  when /darwin/
    DarwinInstaller.install!
  else
    raise "Sorry. Can only install Arduino on Mac OS X. See here for Linux instructions: http://www.arduino.cc/playground/Learning/Linux"
  end

elsif ARGV[0] == "test"
  test_dir = File.expand_path(File.dirname(__FILE__)) + "/../test/hello_world_test"
  puts "Compiling hello_world.cpp to test your Arduino."
  puts "cd #{test_dir}; make depend; make;"
  `cd #{test_dir}; make depend; make;`
  puts
  puts "Compilation successful."
  puts
  puts "Make sure your Arduino is connected and then hit return."
  Readline::readline('')
  
  `cd #{test_dir}; make upload`
  
  # find the USB port to make sure the Arduino's actually plugged in
  options, parser = OptionParser.parse(ARGV)
  usb_port = options["hardware"]["serial_port"]
  port_name = usb_port.split("/").last
  port_dir = usb_port.split("/")[0..(usb_port.split("/").length-2)].join("/")
  unless `ls #{port_dir}`.split(/\n/).any?{|d| d.match(/#{port_name}/)}
    puts
    puts "******************************************************"
    puts "*** It looks like your Arduino is not plugged in.  ***"
    puts "***        Plug it in and try again.               ***"
    puts "***                                                ***"
    puts "***   NOTE: If your usb port is not /dev/tty.usb*  ***"
    puts "***  pass it in to this script with the -p option. ***"
    puts "******************************************************"
  else 
    puts
    puts "******************************************************"
    puts "***                 Success!                       ***"
    puts "***  If your Arduino's light starts blinking soon, ***"
    puts "***     then your Arduino environment is           ***"
    puts "***          correctly configured.                 ***"
    puts "***                                                ***"
    puts "*** Otherwise something is not hooked up properly. ***"
    puts "******************************************************"
  end
  puts
  puts "cleaning up..."
  `rm #{test_dir}/hello_world.hex #{test_dir}/core.a #{test_dir}/hello_world.elf`
else
  # Handle options:
  options, parser = OptionParser.parse(ARGV)
  sketch_name = ARGV[0]
  parser.parse!(["-h"]) unless sketch_name 
    
  
  # Build vendor/rad:  
    
  FileUtils.mkdir_p "#{sketch_name}/vendor/rad"
  puts "Successfully created your sketch directory."
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/rad/.", "#{sketch_name}/vendor/rad"
  puts "Installed RAD into #{sketch_name}/vendor/rad"
  puts
  
  # Build vendor/libraries:  
  
  FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
  puts "Successfully created your libraries directory."
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/AF_XPort/.", "#{sketch_name}/vendor/libraries/AF_XPort"
  puts "Installed AF_XPort into #{sketch_name}/vendor/libraries"
  puts

  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/AFSoftSerial/.", "#{sketch_name}/vendor/libraries/AFSoftSerial"
  puts "Installed AFSoftSerial into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/DS1307/.", "#{sketch_name}/vendor/libraries/DS1307"
  puts "Installed DS1307 into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/FrequencyTimer2/.", "#{sketch_name}/vendor/libraries/FrequencyTimer2"
  puts "Installed FrequencyTimer2 into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/I2CEEPROM/.", "#{sketch_name}/vendor/libraries/I2CEEPROM" 
  puts "Installed I2CEEPROM into #{sketch_name}/vendor/libraries" 
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/LoopTimer/.", "#{sketch_name}/vendor/libraries/LoopTimer" 
  puts "Installed LoopTimer into #{sketch_name}/vendor/libraries" 
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/OneWire/.", "#{sketch_name}/vendor/libraries/OneWire"
  puts "Installed OneWire into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Servo/.", "#{sketch_name}/vendor/libraries/Servo"
  puts "Installed Servo into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Stepper/.", "#{sketch_name}/vendor/libraries/Stepper"
  puts "Installed Stepper into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDpa/.", "#{sketch_name}/vendor/libraries/SWSerLCDpa"
  puts "Installed SWSerLCDpa into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/SWSerLCDsf/.", "#{sketch_name}/vendor/libraries/SWSerLCDsf"
  puts "Installed SWSerLCDsf into #{sketch_name}/vendor/libraries"
  puts
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/libraries/Wire/.", "#{sketch_name}/vendor/libraries/Wire"
  puts "Installed Wire into #{sketch_name}/vendor/libraries"
  puts
  
  # Build examples -- used for basic testing
  
  FileUtils.mkdir_p "#{sketch_name}/vendor/libraries"
  puts "Successfully created your examples directory."
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/examples/.", "#{sketch_name}/examples"
  puts "Installed examples into #{sketch_name}/examples"
  puts
  
  # Build test -- used testing
  
  # FIXME: this should put the tests into the vendor/tests directory instead.
   
  # FileUtils.mkdir_p "#{sketch_name}/test"
  # puts "Successfully created your test directory."
  # 
  # FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/test/.", "#{sketch_name}/test"
  # puts "Installed tests into #{sketch_name}/test"
  # puts
  
  # Build vendor/plugins:  
  
  FileUtils.mkdir_p "#{sketch_name}/vendor/plugins"
  puts "Successfully created your plugins directory."
  
  FileUtils.cp_r "#{File.dirname(__FILE__)}/../lib/plugins/.", "#{sketch_name}/vendor/plugins"
  puts "Installed Default plugins into #{sketch_name}/vendor/plugins"
  puts
  
  # Add an default sketch directory # needed to run test:compile
  
  FileUtils.mkdir_p "#{sketch_name}/#{sketch_name}"
  puts "Successfully created your default sketch directory."
  
  # Build sketch files, etc.:  
  
  FileUtils.touch "#{sketch_name}/#{sketch_name}.rb"
  File.open("#{sketch_name}/#{sketch_name}.rb", "w") do |file|
    file << <<-EOS
  class #{sketch_name.split("_").collect{|c| c.capitalize}.join("")} < ArduinoSketch
    
    # looking for hints?  check out the examples directory
    # example sketches can be uploaded to your arduino with
    # rake make:upload sketch=examples/hello_world
    # just replace hello_world with other examples
    
      def loop
       # your code here
      end
      
  end
    EOS
  end
  puts "Added #{sketch_name}/#{sketch_name}.rb"
  
  File.open("#{sketch_name}/Rakefile", 'w') do |file|
    file << <<-EOS 
  require 'vendor/rad/init.rb'
    EOS
  end
  puts "Added #{sketch_name}/Rakefile"
  
  FileUtils.mkdir_p "#{sketch_name}/config"
  puts "Added #{sketch_name}/config"
  
  File.open("#{sketch_name}/config/hardware.yml", 'w') do |file|
    file << options["hardware"].to_yaml
  end
  puts "Added #{sketch_name}/config/hardware.yml"
  
  File.open("#{sketch_name}/config/software.yml", 'w') do |file|
    file << options["software"].to_yaml
  end
  puts "Added #{sketch_name}/config/software.yml"
  
  puts
  puts "Run 'rake -T' inside your sketch dir to learn how to compile and upload it."
  
  puts "***************************************************"
  puts "***     Please note: This version supports      ***"
  puts "***            Arduino 12 only!                 ***"
  puts "***   run rad install arduino to upgrade        ***"
  puts "***************************************************"
end

================================================
FILE: lib/examples/add_hysteresis.rb
================================================
class AddHysteresis < ArduinoSketch
  
  input_pin 3, :as => :sensor
  output_pin 13, :as => :led


  def loop
    reading = add_hysteresis sensor, 8
    blink led, 100 if reading > 100
    blink led, 1000 if reading <= 100
  end
  
end


================================================
FILE: lib/examples/basic_blink.rb
================================================
class BasicBlink < ArduinoSketch
  # hello world (uncomment to run)
  
  output_pin 13, :as => :led
  
  def loop
    blink led, 100 
    x = 4
  end
end


================================================
FILE: lib/examples/blink_m_address_assignment.rb
================================================
class BlinkMAddressAssignment < ArduinoSketch

  # want to use more than one blink m?
  # since each blink m arrives with the same address, 
  # we can't address each one individually
  # 
  # so the first thing we need to do is give each one a new address
  # that's the purpose of this sketch
  # 
  # install one blinkm at a time
  # a pa_lcd screen makes this easier
  # the screen will start at address ten and increment approximately every
  # four seconds.  Pressing during the first four seconds sets the blnikm 
  # address to 10, during the next four seconds to 11 and so on
  # difficult without a screen.
  # if you need to, program an led to help with the timing
   

  @blink_m_start_address = 10
  @flag = false
  @addr1 = "10, byte"
  @addr2 = "11, byte"
  @addr3 = "12, byte"
  
  output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
  input_pin 7,  :as => :button_one, :device => :button
  input_pin 8,  :as => :button_two, :device => :button
  input_pin 9,  :as => :button_three, :device => :button
  
  output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
  
  def setup
    delay 1000
    my_lcd.setxy 0,0, "bienvenue"
        delay 5000
  end
  
  def loop  
 
    if @flag == false
      staging
    else
      test_address 
    end
    delay 100
  end
  
  def staging
    my_lcd.setxy 0,0, "press button one to"
    my_lcd.setxy 0,1, "set address to "
    my_lcd.print @blink_m_start_address
    my_lcd.setxy 0,2, "or two for status"
    delay 60
    my_lcd.setxy 0,3, "                "
    my_lcd.setxy 0,3
    800.times do |i|
      return 0 if @flag == true
      my_lcd.print "." if i % 50 == 0 
      delay 5
      if button_one.read_input
        assign_address 
      elsif button_two.read_input
        test_address
      end 
    end
    @blink_m_start_address += 1 
  end
  
  def assign_address
    @flag = true
    my_lcd.clearscr "setting to "
    my_lcd.print @blink_m_start_address
    delay 100
    BlinkM_setAddress @blink_m_start_address
    my_lcd.clearscr "done"
    control_it
  end
  
  def control_it
    delay 500
    my_lcd.clearscr "stopping script"
    BlinkM_stopScript @blink_m_start_address
    my_lcd.clearscr "stopping script.."
    delay 500
    my_lcd.clearscr "fade to purple.."
    BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
    my_lcd.clearscr "fade to purple"
    delay 500
    BlinkM_fadeToRGB(@blink_m_start_address, 0xff,0x00,0xff)
  end
  
  
  def test_address
    my_lcd.clearscr
    my_lcd.setxy 0,0, "testing address"
    my_lcd.setxy 0,1
    my_lcd.print blink_m_check_address_message @blink_m_start_address
    delay 5000
  end

  
    

end

================================================
FILE: lib/examples/blink_m_hello.rb
================================================
class BlinkMHello < ArduinoSketch

  # just a scaffolding for blink_m_demo 

  output_pin 19, :as => :wire, :device => :i2c, :enable => :true
  
  def loop

	  x = 4    
  
  end
    

end

================================================
FILE: lib/examples/blink_m_multi.rb
================================================
class BlinkMMulti < ArduinoSketch

  # demonstrate control of individual blinkms
  # this assumes the leds have been assigned addresses 10, 11, 12
  # which can be done with blink m address assignment

  # two ways to address the blinkms, array and individual variables
  @blink_addresses = [10,11,12]
  @addr_all = "0, byte" 
  @addr1 = "10, byte"
  @addr2 = "11, byte"
  @addr3 = "12, byte"
  
  output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin
  input_pin 7,  :as => :button_one, :device => :button
  input_pin 8,  :as => :button_two, :device => :button
  input_pin 9,  :as => :button_three, :device => :button
  input_pin 10,  :as => :button_four, :device => :button
  
  # display the action on a 4x20 pa_lcd, yours may be 9200 instead of 19,200

  output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
  
  
  def loop  
    stop_and_fade(@addr1) if button_one.read_input
    stop_and_fade(@addr2) if button_two.read_input 
    stop_and_fade(@addr3) if button_three.read_input 
    dance if button_four.read_input 
  end
  
  def stop_and_fade(addr)
    f = 1 + addr # hack to coerce addr to int
    my_lcd.clearscr
    my_lcd.setxy 0,0, "blinkm # "
    my_lcd.print addr
    delay 700
    BlinkM_stopScript addr
    my_lcd.setxy 0,1, "stopping script.."
    delay 700
    my_lcd.setxy 0,2, "fade to purple.."
    BlinkM_fadeToRGB(addr, 0xff,0x00,0xff)
  end
  
  def dance
    BlinkM_setFadeSpeed(@addr_all, 20) # 1-255, with 1 producing the slowest fade
    my_lcd.clearscr
    my_lcd.setxy 0,0, "Do the shimmy.."
    my_lcd.setxy 0,1
    @blink_addresses.each do |a|
      BlinkM_fadeToRGB(a, 1,166,138)
      delay 100
    end
    @blink_addresses.each do |a|
      BlinkM_fadeToRGB(a, 35,0,112)
      delay 100
    end
  end
    

end

================================================
FILE: lib/examples/blink_with_serial.rb
================================================
class BlinkWithSerial < ArduinoSketch
  
  # hello world (uncomment to run)
  @i  = "0, long"
  
  output_pin 13, :as => :led
  
  serial_begin
  
    def loop
      @i += 1
      serial_println @i
      blink led, 100 
    end

end


================================================
FILE: lib/examples/configure_pa_lcd_boot.rb
================================================
class ConfigurePaLcdBoot < ArduinoSketch
  
## important!  
## most pa_lcd rates are set to 9200, but there are some newer at 19200
## if you have a 19200, uncomment the end of line 38
  
## purpose:  
## change cursor to none
## and add custom boot screen
## 
## jd's preferred setup for pa_lcd
## 
## assumes 4 x 20 pa_lcd
## 
## no blinking cursor press button 1
## configure custom start up screen - press button 2
## configure lcd to use custom startup screen - press button 3
## 
## press buttons one, two and three 
## or season to taste
##
## refernce
## K107 LCD Controller Board Manual
## page 11 for cursors
## page 13 for custom boot
## http://wulfden.org/downloads/manuals/K107manual.pdf
##
##

## set pins to your setup


   input_pin 8,  :as => :button_one, :device => :button
   input_pin 9,  :as => :button_two, :device => :button
   input_pin 10, :as => :button_three, :device => :button
   
   ## note, most of these controllers are set to 9200
   output_pin 14, :as => :my_lcd, :device => :pa_lcd #, :rate => 19200

   
   def loop
     set_cursor     if button_one.read_input 
     set_custom_screen      if button_two.read_input 
     change_boot_to_custom  if button_three.read_input 
   end
   
   ## assumes 4 x 20 screen
   ## maintain 20 characters after ?Cn
   ## wny delays?  the controller needs them to give it 
   ## enough time to write 20 bytes to internl EEPROM
   def set_custom_screen
     my_lcd.clearscr
     my_lcd.print "?C0   RAD & Arduino    "
     delay 400
     my_lcd.print "?C1    Development     "
     delay 400
     my_lcd.print "?C2                    "
     delay 400
     my_lcd.print "?C3      v0.3.0        "
   end
   
   
   ## ?c0 for no cursor
   ## ?c2 for non blinking cursor
   ## ?c3 for blinking cursor
   def set_cursor
     my_lcd.clearscr
     my_lcd.print "Changing to "
     my_lcd.setxy 0,1
     my_lcd.print "no cursor. "
     my_lcd.setxy 0,3
     my_lcd.print "Reboot to view... "
     
     my_lcd.print("?c0")
   end
   
   ## "?S0 for blank screen 
   ## ?S1 for configuration settings 
   ## ?S2 for custom text screen
   def change_boot_to_custom
     my_lcd.clearscr
     my_lcd.print "Changing to "
     my_lcd.setxy 0,1
     my_lcd.print "custom boot screen. "
     my_lcd.setxy 0,3
     my_lcd.print "Reboot to view... "
     my_lcd.print("?S2")
   end

  
end

================================================
FILE: lib/examples/debounce_methods.rb
================================================
class DebounceMethods < ArduinoSketch
  
  output_pin 13, :as => :led 
  input_pin 6, :as => :button_one, :device => :button # can also :adjust => 300
  input_pin 7, :as => :button_two, :device => :button
  input_pin 8, :as => :button_three, :device => :button
  input_pin 9, :as => :button_four, :device => :button  
  input_pin 10, :as => :button_five, :device => :button  
  
  # depressing and releasing button_one, button_two or button_four do the same thing
  # with a slightly different syntax and number of blinks
  # button_three simply toggles the led with the read_and_toggle method
  # button_five does it with a twist

     def loop
       blink_twice if read_input button_one
       blink_three_times if read_input button_two
       button_three.read_and_toggle led #  
       blink_three_times_basic if read_input button_four
       blink_with_a_twist if read_input button_five
     end
     
     def blink_twice
        2.times do |i|
          led.blink 200 + i
        end
      end
     
     def blink_three_times
       3.times { led.blink 200 }
     end

     # no blink helper
     def blink_three_times_basic
       4.times do 
         led.digitalWrite HIGH
         delay 200
         led.digitalWrite LOW
         delay 200
       end
     end
     
     def blink_with_a_twist
       20.times do |i|
         led.blink i * 10
       end
     end     
     
end

================================================
FILE: lib/examples/external_variable_fu.rb
================================================
class ExternalVariableFu < ArduinoSketch
  
  @one = int
  @two = long
  @three = unsigned
  @four = short
  @five = byte
  @six = 1
  @seven = 1.2
  @eight = "0x00"
  @nine = "arduino"
  @ten = true
  @eleven = false
  @twelve = "1, long"
  @thirteen = "1, unsigned"
  @fourteen = "1, byte"
  @fifteen = HIGH
  @sixteen = LOW
  @seventeen = ON 
  @eighteen = OFF

  def loop
   delay @six
  end
     
end

================================================
FILE: lib/examples/external_variables.rb
================================================
class ExternalVariables < ArduinoSketch

  define "KOOL 10"
  define "TRUE 1"
  define "COMMENT true"
  define "DS1307_CTRL 7"
  define "DS1308_CTRL 7"
  array "char buffer[32];"
  array "char bufferz[32];"


  @foo = 1
  @bidda = "badda"
  @boom = "1, int"
  @rad = "1.00"
  
  def loop
	  delay 1
	  @foo = 2
    @foo = KOOL
  end
  
  def setup # special one time only method
    delay 100
    delay 100
    @foo = 10
    5.times { delay 200 }

  end
    

end

================================================
FILE: lib/examples/first_sound.rb
================================================
class FirstSound < ArduinoSketch



output_pin 11, :as => :myTone, :device => :freq_out, :frequency => 100 # frequency required

    def loop
        myTone.disable
        1.upto(400) { |x| tone_out x }   # run up the scale to 4000 Hz in 10 Hz steps
        399.downto(1) { |x| tone_out x } # come back down in 10 Hz steps
        delay 2000
    end

    def tone_out(n)
        myTone.set_frequency 10*n
        myTone.enable
        delay 80
        myTone.disable
        delay 10
    end
    

end

================================================
FILE: lib/examples/frequency_generator.rb
================================================
class FrequencyGenerator < ArduinoSketch
  
  # need explaination
  
  output_pin 11, :as => :myTone, :device => :freq_out, :frequency => 100

     def loop
         uh_oh 4   
     end

     def uh_oh(n)
       

         n.times do
             myTone.enable
             myTone.set_frequency 1800
             delay 500
             myTone.disable
             delay 100
             myTone.enable
             myTone.set_frequency 1800
             delay 800
             myTone.enable
         end
         # hack to help translator guess that n is an int
         f = n + 0
      end
      

end


================================================
FILE: lib/examples/hello_array.rb
================================================
class HelloArray < ArduinoSketch

 # still working this out...
 # for example, new instance style array declaration naming
 # is at odds with original style array naming  
 
 # for simple integer, string, float, and boolean arrays  
 @toppings = [1,2,3]
 @names = ["ciero", "bianca", "antica"]
 
 # when we just need to declare an array, or need more control, such as specific type requirements
 array "int ingredients[10]"
 array "int pizzas[] = {1,2,3,4}"
 
 output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
 
 
 def loop
   
   my_lcd.clearscr "toppings: "
   delay 500
   
   @toppings.each do |a|
     my_lcd.print a
     my_lcd.print " "
     delay 500
   end
   
   my_lcd.setxy 0,1, "pizzas: "
   
   pizzas.each do |p|
     my_lcd.print p
     my_lcd.print " "
     delay 500
   end
   
   my_lcd.setxy 0,2, "names: "
   
   @names.each do |p|
     my_lcd.print p
     my_lcd.print " "
     delay 500
   end
   
   
 end

end

================================================
FILE: lib/examples/hello_array2.rb
================================================
class HelloArray2 < ArduinoSketch

   # ----------------------------------------------------------------------
   #    Checking out various array operations
   #
   #      JD Barnhart - Seattle, WA July 2008
   #      Brian Riley - Underhill Center, VT, USA  July 2008
   #                     <brianbr@wulfden.org>
   #
   # ----------------------------------------------------------------------

 # still working this out...
 # for example, new instance style array declaration naming
 # is at odds with original style array naming  

 define "THROWAWAY 0"
 
 # for simple integer, string, float, and boolean arrays  
 @toppings = [1,2,3]
 @names = ["ciero", "bianca", "zeus", "athena", "apollo"]
 
 # when we just need to declare an array, or need more control, such as specific type requirements
 array "int ingredients[10]"
 array "int pizzas[] = {1,2,3,4}"
 array "byte buffer[20] = {'A', 'B', 'Z', 'C', 'Y', 'D', 'W', 'E', '%', 'H', '*', '!', ')', '=', 'P', '-', '+', 'R', 'I', 'K'}"
 
 ## multidimensional arrays
 array 'int @my_numbers[3][4] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}'
 array 'char* @pizzas[2][4] = {{"margherita","funghi","napoletana","prosciutto cotto"},{"veggie","pepperoni","cheese","kitchen sink"}}'
 
 
 output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
 
 
 def setup
   
   my_lcd.clearscr "toppings: "
   delay 500
   
   @toppings.each do |a|
     my_lcd.print a
     my_lcd.print " "
     delay 500
   end
   
   my_lcd.setxy 0,1, "pizzas: "
   
   pizzas.each do |p|
     my_lcd.print p
     my_lcd.print " "
     delay 500
   end
   
   my_lcd.setxy 0,2, "names: "
   
   @names.each do |p|
     my_lcd.print p
     my_lcd.print " "
     delay 500
   end
   
   delay 3000
   

   
   my_lcd.clearline 1, @names[2]
   my_lcd.print " [ "
   my_lcd.print pizzas[1]
   my_lcd.print " ]"
   
   delay 2000
   
   my_lcd.clearscr "Multidimensional ?n"
   
   0.upto(2) do |f|
     0.upto(3) do |s|
       my_lcd.print @my_numbers[f][s]
       my_lcd.print ", "
       delay 500
     end
   end
   
   delay 1000
   
   my_lcd.clearscr

    0.upto(1) do |f|
      0.upto(3) do |s|
        my_lcd.print @pizzas[f][s]
        my_lcd.print ", "
        delay 500
      end
    end



    delay 2000
   
   my_lcd.clearscr "Array Load?n"
   1.upto(20) do |x|
#     buffer[x] = 64 + x  # we cannot set array elements yet except to initialize in declaration
     my_lcd.print buffer[x-1]
     my_lcd.print " "
   end
   
 end
 
 def loop
    x = THROWAWAY
 end

end

================================================
FILE: lib/examples/hello_array_eeprom.rb
================================================
class HelloArrayEeprom < ArduinoSketch

   # ----------------------------------------------------------------------
   #    Checking out various array operations  with I2C serial EEPROM
   #      doing block writes and bloack readbacks with byte arrays
   #
   #      JD Barnhart - Seattle, WA July 2008
   #      Brian Riley - Underhill Center, VT, USA  July 2008
   #                     <brianbr@wulfden.org>
   #
   # ----------------------------------------------------------------------

 # still working this out...
 # for example, new instance style array declaration naming
 # is at odds with original style array naming  

 define "THROWAWAY 0"

 # when we just need to declare an array, or need more control, such as specific type requirements
 array "byte page_data[20] = {'R', 'A', 'D', ' ', 'i', 's', ' ', 'B', 'A', 'D', '*', '!', ')', '=', 'P', '-', '+', 'R', 'I', 'K'}"
 array "byte in_buffer[20]"
 
 output_pin 19, :as => :mem0, :device => :i2c_eeprom, :address => 1     # w/o :address defaults to  :address => 0  which is  0x50
 output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 19200
 
 
 def setup
   
   my_lcd.clearscr    "  I2C EEPROM Demo"
   my_lcd.setxy 0, 1, "block write and read"
   my_lcd.setxy 0, 2, "  back and display"
   my_lcd.setxy 0, 3, "    to the LCD"
   
   delay 2000
   
   my_lcd.clearscr    "  I2C EEPROM Demo?n    block write"

   mem0.write_page 0x0100, page_data, 20 

   delay 1000
   
   my_lcd.clearline 1, "  block readback"
   
   mem0.read_buffer 0x0100, in_buffer, 20 
   
   my_lcd.setxy 0, 2
   
   1.upto(20) do |x|
     my_lcd.print in_buffer[x-1]
     my_lcd.print " "
   end
   
 end
 
 def loop
    x = THROWAWAY
 end

end

================================================
FILE: lib/examples/hello_clock.rb
================================================
class HelloClock < ArduinoSketch
  
# ----------------------------------------------------------------------------------
#   <b>Time and Temp  (20 July 2008)</b>
#   Example #1 - Brian Riley, Underhill Center, VT USA <brianbr@wulden.org>
#   
#   Connections
#     I2C bus - DS1307 Real Time Clock chip
#     Analog 0 (a.k.a Digital 14) - Wulfden K107 seria LCD Controller
#                                   Peter Anderson chip
#
#   Comment
#     - This is a straight forward program to read the Real Time Clock and Display
#     delay() calls waiting for temperature conversion readings
#
#     - for the external data busses make sure you have 4.7K pullup resistors on the 
#      the SDA/SCL (I2C)
#
# ----------------------------------------------------------------------------------
 
    @flag    = int

    array "byte clock[8]"
    
    @days   = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]
    @months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

                              # implicit in :device => :ds1307 is that this i i2c
                              # :enable => true issues the Wire.begin to ick over i2c
    output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true
                              # software serial tx drives LCD display, screen cleared at startup
                              # defines the softare protocol for controller as Peter Anderson
    output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
    loop_timer :as => :mainloop
    

    def setup
      myLCD.clearscr "   --<Date/Time>--"
      myLCD.setxy 1,3, "looptime = "
      rtc.get clock, 1
      print_main
      @flag = 1
    end
    
    def loop
        mainloop.track
        myLCD.setxy 12,3,  mainloop.get_total
        rtc.get clock, 1
        if clock[0] == 0
          if @flag == 0
            print_main
            @flag = 1
          end
        else
          @flag = 0
        end
       	myLCD.setxy 6,2
       	printlz clock[2]
       	myLCD.print ":"
  	    printlz clock[1]
       	myLCD.print ":"
  	    printlz clock[0]

       delay 50
        
    end

    def	printlz(w)
    			myLCD.print "0" if w < 10
    			myLCD.print w
    end

    def	print_main
 	    myLCD.setxy 1,1, @days[clock[3]-1]
		  myLCD.print ", "
      myLCD.print @months[clock[5]-1]
   	  myLCD.print " "
      printlz clock[4]
   	  myLCD.print ", "
      printlz clock[6] + 2000
      
    end
    
end


================================================
FILE: lib/examples/hello_eeprom.rb
================================================
class HelloEeprom < ArduinoSketch
  
  output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true
  output_pin 19, :as => :mem0, :device => :i2c_eeprom

  output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200
    
  def loop
	    myLCD.setxy 0,0					# set to 0,0
	    myLCD.print rtc.get(5, 1)	# refresh registers (=1) get month
     	myLCD.print "/"
	    myLCD.print rtc.get(4, 0)	# no need to refresh (=0) get day 
     	myLCD.print "/"
	    myLCD.print rtc.get(6, 0)	# get year
     	myLCD.setxy(0,1)			# set in 1 byte line 1 (second line)
     	printlz 2					# print hours with lead zero
     	myLCD.print ":"
	    printlz 1					# print minutes with lead zero
     	myLCD.print ":"
	    printlz 0					# print seconds with lead zero
	    

		myLCD.setxy 10,0
		myLCD.print "write test"
		myLCD.setxy 0,2
		32.upto(109) do				# write address of byte to that b yte
			|x| mem0.write_byte  x, x
			myLCD.print(".") if x%2
			delay 10
		end

		delay 2000
		
		myLCD.clearline 2 	# clears bottom two lines           
		myLCD.clearline 3

		myLCD.setxy 10,0, "read test "
		myLCD.setxy 0,2
									# read and print 39 addresses with printable numbers
		75.upto(113) { |x| myLCD.print(mem0.read_byte(x)) }
		delay 10000
		myLCD.clearscr
  end
  
  def	printlz(w)
  			i = 0 + rtc.get(w,0)         # the '0 +' is YARH (Yet Another RubyToc Hack)
  			myLCD.print "0" if i < 10
  			myLCD.print i
  end

end


================================================
FILE: lib/examples/hello_eeprom_lcdpa.rb
================================================
class HelloEepromLcdpa < ArduinoSketch
  # -----------------------------------------------------------------------
  #    Simple Byte Write and Byte Read-back of I2C EEPROM
  #
  #      Brian Riley - Underhill Center, VT, USA  July 2008
  #                     <brianbr@wulfden.org>
  #
  #    I2C Routines are in a plugin not a library
  #    No block reads and write yet
  #    Displays to PH Anderson based serial LCD Display
  #
  #    <b>I2C Serial EEPROM - Byte Read and Byte Write</b>
  #      
  #     i2c_eeprom_write_byte  dev_addr, chip_addr, value
  #
  #     dev_addr (byte) - range 0x50 to 0x57 determined by hardware wiring 
  #     chip_addr (unsigned) - 0 to as much as 64K, depends on chip
  #     value (byte) - 0 to 255 (0x00 to 0xFF)
  #
  #     returns - nothing
  #
  #     i2c_eeprom_read_byte  dev_addr, chip_addr
  #
  #     dev_addr (byte) - range 0x50 to 0x57 determined by hardware wiring 
  #     chip_addr (unsigned) - 0 to as much as 64K, depends on chip
  #
  #     returns - byte value
  #
  #
  #     http://www.arduino.cc/playground/Code/I2CEEPROM
  # ----------------------------------------------------------------------
  
  output_pin 19, :as => :mem0, :device => :i2c_eeprom, :enable => :true
  output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200


    
  def setup
      delay 1500        # give startup screen time to finish and clear
	    myLCD.clearscr    "  I2C EEPROM Demo"
      myLCD.setxy 0, 1, "byte write then read"
      myLCD.setxy 0, 2, "  back and display"
      myLCD.setxy 0, 3, "    to the LCD"
      
      clear_off_test
      myLCD.clearline 1, "  byte write test"
      
      myLCD.setxy 0, 2
      32.upto(109) do				# write address of byte to that b yte
			  |x| mem0.write_byte  x, x+7
        myLCD.print(".") if x%2
        delay 10      # EEPROM write _requires_ 3-10 ms pause
      end

      clear_off_test
      myLCD.clearline 1, "  byte read test "

      myLCD.setxy 0, 2
									# read and print 39 addresses with printable numbers
      70.upto(105) { |x| myLCD.print(mem0.read_byte(x)) }

      delay 2000
      clear_off_test
      myLCD.clearline 1, "-< tests complete >- "


  end
  
  def loop
    x = 4       # loop has to have _something_
  end


   def clear_off_test   # clears bottom two lines 
     delay 2000
     myLCD.clearline 3
     myLCD.clearline 2   # leaves you at start of a 
                              # cleared third line
   end

end


================================================
FILE: lib/examples/hello_format_print.rb
================================================
class HelloFormatPrint < ArduinoSketch

  # ----------------------------------------------------------------------
  #    Demonstrattion of Crude Adaptaion of C Function sprintf()
  #    to do formatted printing. For now there are some absolutes:
  #    The write_line method atkes as arguemnst the formatting string
  #    and the appropriate arguments. It format them to an internal
  #    buffer sepcified and created when you invoke formatted printing
  #       formatted_print :as => :line_buf, :buffer_size => 80
  #    now, to actual do it you use write_line
  #       write_line "Pies $%02d.%02d", pie_cents/100, pie_cents%100
  #    then print the string pointed at by string_line
  #       my_lcd.setxy 3, 2, line_buf 
  #
  #      Brian Riley - Underhill Center, VT, USA  Aug 2008
  #                     <brianbr@wulfden.org>
  #
  # ----------------------------------------------------------------------

# demonstrate 4 x 20 pa_lcd toggle between normal and Bignum mode
# with @toggle external variable thrown in for fun

# change your pins to suit your setup
  
  @toggle = "0, int"
  @pie_cents = "403, int"
  @pie_price = "7.08"

  
  input_pin 8,  :as => :button_one, :device => :button
  input_pin 9,  :as => :button_two, :device => :button
  input_pin 10, :as => :button_three, :device => :button
  
  formatted_print :as => :string_line, :buffer_size => 65   # generally this statement should precede any serial_begin or
                                                            # LCD display directive

  output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true

  
  def setup
    my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
  end
  
  def loop 
    if millis % 500 == 0
      write_line "millis()= %ld", millis
      my_lcd.setxy 1, 2, string_line
    end 
    say_hello     if button_one.read_input 
    say_more      if button_two.read_input 
    say_it_large  if button_three.read_input 
  end
  
  def say_hello
    @toggle = true
    my_lcd.clearscr "This sketch has?nbeen running for?n "
    write_line "%ld mins and %d secs?n", millis/60000, (millis/1000)%60
    my_lcd.print string_line
    delay 3000
    my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
  end
  
  def say_more # passing print strings to home and setxy (also works on clearscr)
    @toggle = false
    my_lcd.clearscr "Food Store Prices"
    write_line "Pies $%2d.%02d", @pie_cents/100, @pie_cents%100
#    write_line "Pies $%6.2f", @pie_price # float doessn't seem to work .....
    my_lcd.setxy 2, 1, string_line
#    write_line "toggle state is [%s]", @toggle ? "ON" : "OFF"  # RubyToC screws this construct up and RAD mistajekl put 1 ad 0
                                                                # in place of "ON" and "OFF"
    write_line "toggle state is [%d]", @toggle
    my_lcd.setxy 2, 3, string_line
    delay 3000
    my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"
  end
  
  
  def say_it_large

    my_lcd.intoBignum
    my_lcd.clearscr            # line 0, col 0
    1.upto(32) do |i|
      my_lcd.setxy 0,1
      my_lcd.print i * i
      delay 200
    end
    my_lcd.outofBignum
    delay 3000
    my_lcd.clearscr " --<Press Button>--?nOne, Two, or Three"      
  end
  

 
end

================================================
FILE: lib/examples/hello_lcd_charset.rb
================================================
class HelloLcdCharset < ArduinoSketch

  # -------------------------------------------------------------------------
  #    Program to Display the entire lower half (under 0x80) character set
  #
  #    The class variable @a defined as byte is needed to make RubyToC put
  #    the value to be 'printed' as a byte and thus give us the character
  #    that value represents.
  #
  #      Brian Riley - Underhill Center, VT, USA  July 2008
  #                     <brianbr@wulfden.org>
  #
  # ----------------------------------------------------------------------
  
   
      @a  = byte
      
      output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200
      output_pin 13, :as => :led

  def loop
    
    myLCD.clearscr  "Alphabet Chars?n"
    0x41.upto(0x5a) do |i|    # A to Z
      @a = i                  # forces 'byte' typing to variable
      myLCD.print @a          # so print rouien prints character represented 
      delay 50                # by the index value
    end
    0x61.upto(0x7a) do |i|    # a to z
      @a = i
      myLCD.print @a
      delay 50
    end
    
    delay 3000
    myLCD.clearscr  "Numeric Chars?n"
    0x30.upto(0x39) do |i|    # 0 to 9
      @a = i
      myLCD.print @a
      delay 50
    end
    
    delay 3000

    myLCD.clearscr  "Other Chars?n"
    0x21.upto(0x2f) do |i|    # punctuation et al
      @a = i
      myLCD.print @a
      delay 50
    end
    0x3a.upto(0x40) do |i|
      @a = i
      myLCD.print @a
      delay 50
    end
    0x5b.upto(0x60) do |i|
      @a = i
      myLCD.print @a
      delay 50
    end
    0x7b.upto(0x7f) do |i|
      @a = i
      myLCD.print @a
      delay 50
    end
    
    delay 3000
      


  end
  
  
  
end

================================================
FILE: lib/examples/hello_pa_lcd.rb
================================================
class HelloPaLcd < ArduinoSketch


# demonstrate 4 x 20 pa_lcd toggle between normal and Bignum mode
# with @toggle external variable thrown in for fun

# change your pins to suit your setup
  
  @toggle = false
  
  input_pin 6,  :as => :button_one, :device => :button
  input_pin 7,  :as => :button_two, :device => :button
  input_pin 8, :as => :button_three, :device => :button
  
  output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true

  def setup
    delay 3000
    my_lcd.setxy 0,0
    my_lcd.print "Press button"
    my_lcd.setxy 0,1
    my_lcd.print "One, two or three...."
  end
  
  def loop  
    say_hello     if button_one.read_input 
    say_more      if button_two.read_input 
    say_it_large  if button_three.read_input 
  end
  
  def say_hello
    @toggle = true
    my_lcd.clearscr "Any sufficiently    advanced technology"
    my_lcd.setxy 0,2
    my_lcd.setxy 0,3, "toggle state: "
    my_lcd.print @toggle
  end
  
  def say_more # passing print strings to home and setxy (also works on clearscr)
    @toggle = false
    my_lcd.clearscr "is indistinguishablefrom magic"
    my_lcd.setxy 0,3, "toggle state: "
    my_lcd.print @toggle
  end
  
  
  def say_it_large

    my_lcd.intoBignum
    my_lcd.clearscr            # line 0, col 0
    1.upto(32) do |i|
      my_lcd.setxy 0,1
      my_lcd.print i * i
      delay 200
    end
    my_lcd.outofBignum
  end
 
end

================================================
FILE: lib/examples/hello_servos.rb
================================================
class HelloServos < ArduinoSketch
  
  output_pin 2, :as => :servo_1, :max => 2400, :min => 800
  output_pin 3, :as => :servo_2, :max => 2400, :min => 800
  output_pin 4, :as => :servo_3, :max => 2400, :min => 800


     # time to go old school
     def loop
       song_sheet_two
     end
     
     def song_sheet_two
       e
       d
       e
       d 
       c
       d
       d
       c
       b
       c
       b
       a
       e
       a
       e
       a
       e
       a
       b
       c
       b
       c
       d
       d
       c
       d
       e
       d
       e
     end
     
     def a
       pulse_servo servo_1, 1450
       delay 100
       home servo_1
       delay 20
     end

     def b
       pulse_servo servo_1, 1350
       delay 100
       home servo_1
       delay 20
     end

     def c
       pulse_servo servo_2, 1450
       delay 100
       home servo_2
       delay 20
     end

     def d
       pulse_servo servo_2, 1350
       delay 100
       home servo_2
       delay 20
     end

     def e
       pulse_servo servo_3, 1500
       delay 100
       home servo_3
       delay 20
     end


     # center servos

     def home(s)
       pulse_servo s, 1400
       f = s + 0
     end

end

================================================
FILE: lib/examples/hello_spectra_sound.rb
================================================
class HelloSpectraSound < ArduinoSketch

  # demonstrate capability to use soft pot as traditional pot
  # the last pot reading remains "locked" to the last touch point
  # similar same behavior as ipod
  #
  # this sketch assumes a pa_lcd operating at 19200 and one 
  # spectra symbol softpot connected to analog pin 3
  # 
  @reading  = int
  output_pin 14, :as => :my_lcd, :device => :pa_lcd, :rate => 9600, :clear_screen => :true
  output_pin 11, :as => :sound, :device => :freq_out, :frequency => 100, :enable => :true
  input_pin 3, :as => :sensor_one, :device => :spectra


   def setup
     delay 1000
     my_lcd.setxy 0,0, "spectra symbol"
     my_lcd.setxy 0,1, "soft pot sound"
     delay 3000
     my_lcd.clearscr
   end

   def loop
     my_lcd.setxy 0,1
     # since lcd's have issues clearing tens and hundreds digits when reading ones, 
     # we use pad_int_to_str, which is a hack to display these cleanly
     # pad_int_to_str takes two arguments: an integer and the final string length
     # 
#     my_lcd.print pad_int_to_str analogRead(sensor_one), 5
     @reading = sensor_one.soft_lock
     sound.set_frequency @reading * 10
     my_lcd.print pad_int_to_str @reading, 3
     delay 30
   end
    

end

================================================
FILE: lib/examples/hello_world.rb
================================================
class HelloWorld < ArduinoSketch
  
  output_pin 13, :as => :led

  def loop
    blink led, 100
  end

end




================================================
FILE: lib/examples/hello_xbee.rb
================================================
class HelloXbee < ArduinoSketch
  
  output_pin 13, :as => :led
  
  serial_begin
  def loop
    led.blink 200
    serial_print "...testing..."
    delay 1000
  end
  
end

================================================
FILE: lib/examples/hysteresis_duel.rb
================================================
class HysteresisDuel < ArduinoSketch
  
  # purpose 
  # side by side demo of affect of hysteresis on two different sensor readings
  # 
  #

  # requires one pa_lcd
  # two sensors or potentiometers



    output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
    input_pin 1, :as => :sensor_one, :device => :sensor
    input_pin 2, :as => :sensor_two, :device => :sensor

    def setup
      delay 1000
      my_lcd.setxy 0,0, "hysteresis duel"
      delay 5000
      my_lcd.clearscr
    end

    def loop
      my_lcd.setxy 0,0, "direct"
      my_lcd.setxy 0,1, "one: "
      my_lcd.print analogRead sensor_one
      my_lcd.print " two: "
      my_lcd.print analogRead sensor_two
      my_lcd.setxy 0,2, "with hysteresis"
      my_lcd.setxy 0,3, "one: "
      my_lcd.print sensor_one.with_hyst 4
      my_lcd.print " two: "
      my_lcd.print sensor_two.with_hyst 4
      delay 230
    end

    
end


================================================
FILE: lib/examples/i2c_with_clock_chip.rb
================================================
class I2cWithClockChip < ArduinoSketch
  
# ----------------------------------------------------------------------------------
#   <b>Time and Temp  (20 July 2008)</b>
#   Example #1 - Brian Riley, Underhill Center, VT USA <brianbr@wulden.org>
#   
#   Connections
#     I2C bus - DS1307 Real Time Clock chip
#     Analog 0 (a.k.a Digital 14) - Wulfden K107 seria LCD Controller
#                                   Peter Anderson chip
#     Digital 8 - Dallas SemiConductor DS18B20 One-Wire temperature Sensor (12 bit)
#
#   Comment
#     - This is a straight forward, program with minimal error checking and brute force
#     delay() calls waiting for temperature conversion readings
#
#     - for the external data busses make sure you have 4.7K pullup resistors on the 
#     data line (OnewWire) and the SDA/SCL (I2C)

# ----------------------------------------------------------------------------------
 
    @hi_byte    = int
    @lo_byte    = int
    @t_reading  = int
    @device_crc = int
    @sign_bit   = int
    @tc_100     = int
                              # implicit in :device => Z:ds1307 is that this i i2c
                              # :enable => true issues the Wire.begin to ick over i2c
    output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true
                              # software serial tx drives LCD display, screen cleared at startup
                              # defines the softare protocol for controller as Peter Anderson
    output_pin 14, :as => :myLCD, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
                              # defines  this pin as being connected to a DalSemi 1-Wire device
                              # no specific device drivers yet, the specific device code is on you
    output_pin 8, :as => :myTemp, :device => :onewire


    def loop
  		  until myTemp.reset do   # reset bus, verify its clear and high
  		    clear_bottom_line
  		    myLCD.print " <1Wire Buss Error>"
  		    delay 2000
  		  end
   		
    		myTemp.skip                 # "listen up - everybody!"
    		myTemp.write 0x44, 1        # temperature sensors, strta conversion

    		myLCD.setxy 6,0             # while they do that, lets print date/time
  	    myLCD.print rtc.get(5, 1)
       	myLCD.print "/"
  	    myLCD.print rtc.get(4, 0)
       	myLCD.print "/"
  	    myLCD.print rtc.get(6, 0)
       	myLCD.setxy 6,1
       	printlz rtc.get(2, 0)
       	myLCD.print ":"
  	    printlz rtc.get(1, 0)
       	myLCD.print ":"
  	    printlz rtc.get(0, 0)

    		delay 800                   # conversion takes about 750 msecs

    		until myTemp.reset do       # reset bus, verify its clear and high
    		  clear_bottom_line
    		  myLCD.print " <1Wire Buss Error>"
    		  delay 2000
    		end
     		myTemp.skip                 # listen up!
    		myTemp.write 0xBE, 1        # send me your data conversions

        @lo_byte = myTemp.read      # get irst byte
        @hi_byte = myTemp.read      # get second byte
        
        # -------------------------------------------------------------
        clear_bottom_line       # this code is debug - not necessary
        myLCD.setxy 4,3         # raw hex display of temp value
        myLCD.print "raw = 0x"
        print_hexbyte @hi_byte  # prints 2 digit hex w/lead 0
        print_hexbyte @lo_byte
        # -------------------------------------------------------------

        7.times { @device_crc = myTemp.read } # get next 6 bytes, drop them on floor
                                              # next byte the ninth byte is the CRC
        
                                # DS18B20 brings data temperature back as 12 bits
                                # in degrees centigrade with 4 bits fractional, that is 
                                # each bit s 1/16 of a degreeC
                                
        @t_reading  =   build_int @hi_byte, @lo_byte
        @sign_bit   =   bit_and @t_reading, 0x8000
        @t_reading  =   twos_comp @t_reading   if @sign_bit  # negative

        @tc_100 = (6 * @t_reading) + (@t_reading / 4)   #multiply by (100 * 0.0625) or 6.25

        myLCD.setxy 2,2
        if @sign_bit
            myLCD.print "-"
        else
            myLCD.print " "
        end
        myLCD.print(@tc_100 / 100)             # separate off the whole 
        myLCD.print "."
        printlz(@tc_100 % 100)                  # and fractional portions
        myLCD.print " degrees C"

    end

    def	printlz(w)
    			myLCD.print "0" if w < 10
    			myLCD.print w
    end

    def	print_hexbyte(w)
    			myLCD.print "0" if w < 0x10
    			myLCD.print w, 0x10
    end

    def clear_bottom_line
		      myLCD.setxy 0,3
		      myLCD.print "?l"
    end
    
end


================================================
FILE: lib/examples/midi_beat_box.rb
================================================
class MidiBeatBox < ArduinoSketch
  
  # midi synthesiser output on channel 2
  # with speed controlled by spectra soft pot

    @channel = 2
    input_pin 1, :as => :sensor_one, :device => :spectra
    output_pin 13, :as => :led

    serial_begin :rate => 31250

    def setup
      delay 3000
    end

    def loop
      8.times {first}
      2.times do 
        second
        third
      end
      4.times {first}
      2.times {second}
    end
    
    def first
      play 39, 52, 37
      play  0,  0,  0
      play 36, 52,  0
      play 37, 52, 39

      play 37,  0,  0
      play 36,  0,  0
      play 39, 50,  0
      play  0,  0,  0

      play 52, 36, 37
      play 0,  0,   0
      play 39,  0,  0
      play 36, 37,  0

      play 36, 37, 39
      play 36, 38,  0
      play 50,  0,  0
      play 0,   0,  0
    end
    
    def second
      play 39, 52, 37
      play 36,  0,  0
      play  0,  0,  0
      play 37, 52, 39

      play 38,  0,  0
      play 36,  0,  0
      play 39, 50,  0
      play  0,  0,  0
    end
    
    def third
      play  0, 36, 37
      play  0,  0,   0
      play 39, 36,  0
      play 36, 37, 50

      play 36, 37, 39
      play 36, 37,  0
      play 50,  0,  0
      play 39,  0,  0
    end
    

    def play(one, two, three)
      n = 1 + one + two + three # ack to coerce parameters to int
      note_on(@channel, one, 127) unless one == 0
      note_on(@channel, two, 127) unless two == 0
      note_on(@channel, three, 127) unless three == 0
      delay 310 - sensor_one.soft_lock # start slowly 
      note_off(@channel, one, 0) unless one == 0
      note_off(@channel, two, 0) unless two == 0
      note_off(@channel, three, 0) unless three == 0
    end
    

    
end

================================================
FILE: lib/examples/midi_scales.rb
================================================
class MidiScales < ArduinoSketch
  
# purpose
# trigger midi output with buttons and
# spectra soft pots
#
#


  @current_note = int
  @last_note_one = 0
  @last_note_two = 0
  @last_note_three = 0
  @note = int

  input_pin 1, :as => :sensor_one, :device => :spectra
  input_pin 2, :as => :sensor_two, :device => :spectra
  input_pin 3, :as => :sensor_three, :device => :spectra
  input_pin 7, :as => :button_one, :device => :button
  input_pin 8, :as => :button_two, :device => :button
  input_pin 9, :as => :button_three, :device => :button
  output_pin 13, :as => :led

  serial_begin :rate => 31250

  def setup
    delay 3000
  end

  def loop
    change_tone if button_one.read_input
    change_pressure if button_two.read_input
    change_channels if button_three.read_input
    read_sensor_one
    read_sensor_two
    read_sensor_three
  end
     
  def change_tone 
    110.upto(127) do |note|
      play 0, note, 127
    end
  end

  def change_pressure
    110.upto(127) do |pressure| 
       play 0, 45, pressure
    end
  end
     
  def change_channels 
    0.upto(6) do |channel| 
      play channel, 50, 100
    end
  end

  def read_sensor_one
    @current_note = sensor_one.soft_lock
    pre_play(@current_note, @last_note_one, 13)
    @last_note_one = @current_note
  end

  def read_sensor_two
    @current_note = sensor_two.soft_lock
    pre_play(@current_note, @last_note_two, 14)
    @last_note_two = @current_note
  end

  def read_sensor_three
    @current_note = sensor_three.soft_lock
    pre_play(@current_note, @last_note_three, 15)
    @last_note_three = @current_note
  end

  def pre_play(current_note, last_note, channel) # warning, don't use last as a parameter...
    n = 1 + channel
    unless current_note == last_note
      @note = ((current_note /16) + 40)
      play_with_no_delay( channel, @note, 100 )
    end
  end
    
  def play(chan, note, pressure)
    note_on(chan, note, pressure)
    delay 100 # adjust to need
    note_off(chan, note, 0)
  end
  
  def play_with_no_delay(chan, note, pressure) # note is not turned off
    note_on(chan, note, pressure)
  end


end


================================================
FILE: lib/examples/motor_knob.rb
================================================
class MotorKnob < ArduinoSketch

# ----------------------------------------------------------
#    MotorKnob adapted from Tom Igoe's Arduino Sketch
#
#      Brian Riley - Underhill Center, VT, USA  July 2008
#                     <brianbr@wulfden.org>
#
#    A stepper motor follows the turns of a potentiometer
#    (or other sensor) on analog input 0.
#
#     http://www.arduino.cc/en/Reference/Stepper
# ----------------------------------------------------------

  fourwire_stepper  8, 9, 10, 11, :as => :mystepper, :speed => 31, :steps => 200
  input_pin  0, :as => :sensor
  
  
  @previous = "0, int"
  @value    = "0, int"
  
  def loop
    
    @value = analogRead(sensor)
    mystepper.set_steps @value - @previous
    @previous = @value 
    
  end

end

================================================
FILE: lib/examples/servo_buttons.rb
================================================
class ServoButtons < ArduinoSketch
  
  # original syntax
  input_pin 6, :as => :button_one, :latch => :off
  # preferred syntax
  input_pin 7, :as => :button_two, :device => :button
  input_pin 8, :as => :button_three, :device => :button
  output_pin 13, :as => :led 
  output_pin 2, :as => :my_servo, :device => :servo 
  

  def loop
   check_buttons
   servo_refresh 
  end

  def check_buttons
  	read_and_toggle button_one, led
  	my_servo.position 180 if read_input button_two
  	my_servo.position 60 if read_input button_three
  end
  
end

================================================
FILE: lib/examples/servo_calibrate_continuous.rb
================================================
class ServoCalibrateContinuous < ArduinoSketch

  # ----------------------------------------------------------------------
  #    Program to calibrate a 'continuous' or 'modified' hobby servo
  #
  #    Basically uses teh servo 'spped' command to send a speed
  #    of zero (0) to the servo continuously. You then use a small
  #    screwdriver to adjust the potentiometer on the sero until there
  #    is no motion whatsoever.
  #
  #    The program strats off by commanding max speed clockwise and then
  #    counter clockwise. First the LED blinks rapidly for 2 seconds as
  #    a warning that motion is coming. Then the LED is turned on solid
  #    Then 2 seconds max rev clockwise, then two seconds max rev counter-
  #    clockwise. Then the LED is turned off and this followed by twenty
  #    second of the servo commanded to zero (0) speed. During this time
  #    you may adjust the servo for no motion. If you stilll have more
  #    adjustmenst to make you will be warned by the flashing LED to
  #    back off while it moves back and forth. This full speed motion
  #    is to let you knwo you have it right,
  #
  #    The 20 second timer uses the Arduino millis() counter which
  #    rolls over after a couple million milliseconds. I made no attempt
  #    to allow for ths. If your servo isn't calibrated after a couple
  #    million milliseconds and the prgram jams up then (a) hit the reset
  #    button, or (b) give up!
  #
  #      Brian Riley - Underhill Center, VT, USA  July 2008
  #                     <brianbr@wulfden.org>
  #
  # ----------------------------------------------------------------------
  
   
  @test_state = "2, int"
  @cycle_time = "0, long"
  
  
      # This sets up to do four units at once
      # You can comment the extra lines out or leave them in, if there's nothing
      # connected, no harm, no foul!
      output_pin 12, :as => :servo4, :device => :servo, :minp => 400, :maxp => 2600
      output_pin 11, :as => :servo3, :device => :servo, :minp => 400, :maxp => 2600
      output_pin 10, :as => :servo2, :device => :servo, :minp => 400, :maxp => 2600
      output_pin  9, :as => :servo1, :device => :servo, :minp => 400, :maxp => 2600
 
      output_pin 13, :as => :led



  def loop
    if @test_state == 2

      40.times { blink led, 50 }    # 40 x 50 ms is a 2 second blinking light
                                    #  ** Warning! **  "... danger Will Robinson!"
      toggle led                    # turn it on keep it on -- keep hands away
      servo1.speed -90
      servo2.speed -90
      servo3.speed -90
      servo4.speed -90
      delay_servo 2000              # two full seconds max clockwise
      servo1.speed 90
      servo2.speed 90
      servo3.speed 90
      servo4.speed 90
      delay_servo 2000              # two full seconds max counter clockwise
      
      @test_state = 1               # setup for zero speed test/adjust
      @cycle_time = millis + 20000
      servo1.speed 0
      servo2.speed 0
      servo3.speed 0
      servo4.speed 0
      toggle led                    # lights off, OK  you have 20 seconds to adjust
    end

    if @cycle_time - millis <= 0
        @test_state = 2
    else
        servo_refresh
    end
        
  end
  
  
  def delay_servo(t)
    t.times do
      delay 1
      servo_refresh
    end
  end
  
end

================================================
FILE: lib/examples/servo_throttle.rb
================================================
class ServoThrottle < ArduinoSketch

     # updated 20080731 
     # replaced external variables with instance style variables
     
     # potentiometer to control servo
     # with a bit of hysteresis
     # use analog pin for sensor
     # need to format the output of sensor_position and sensor_amount

     @sensor_position = 0
     @servo_amount = 0

     output_pin 5, :as => :my_lcd, :device => :sf_lcd
     input_pin 1, :as => :sensor
     output_pin 2, :as => :my_servo, :device => :servo


       def loop
         servo_refresh
         #delay 9 # comment out if using servo status, since it will add enough delay
         @sensor_position = analogRead(sensor)
         @servo_amount = (add_hysteresis(@sensor_position, 10)*0.36)
         my_servo.position @servo_amount
         servo_status
         
       end
       
       def servo_status
         
        my_lcd.setxy 0,0			# line 0, col 0
     		my_lcd.print "Read  Send"
     		my_lcd.setxy 0,1		# line 1, col 0
     		my_lcd.print @sensor_position # need method of blanking out previous reading
     		my_lcd.setxy 6,1 
     		my_lcd.print @servo_amount
       end

  
end

================================================
FILE: lib/examples/software_serial.rb
================================================
class SoftwareSerial < ArduinoSketch
  output_pin 13, :as => :led
  software_serial 6, 7, :as => :gps
  serial_begin

  def loop
    digitalWrite(led, true)
    serial_print(gps.read)
  end
end

================================================
FILE: lib/examples/sparkfun_lcd.rb
================================================
class SparkfunLcd < ArduinoSketch


  input_pin 6, :as => :button_one, :latch => :off
  input_pin 7, :as => :button_two, :latch => :off
  input_pin 8, :as => :button_three, :latch => :off
  output_pin 13, :as => :led
  
  swser_LCDsf 5, :as => :my_lcd
  



#serial_begin # not necessary when using :device => :sf_lcd or :pa_lcd

  def loop
   check_buttons
  end
  

# need a bit

  def say_hello
    my_lcd.setxy 0,0			# line 0, col 0
		my_lcd.print "All your base   "
		my_lcd.setxy 0,1		# line 1, col 0
		my_lcd.print "are belong to us"
  
  end 
  
  def	say_ruby
		my_lcd.setxy 0,0			# line 0, col 0
		my_lcd.print " Ruby + Arduino "
		my_lcd.setxy 0,1		# line 1, col 0
		my_lcd.print " RAD 0.2.4+     "
		# un comment to change display startup
		#myLCD.setcmd 0x7C, 10
	end

  def check_buttons
  	read_and_toggle button_one, led
  	say_hello if read_input button_two
  	say_ruby if read_input button_three
  	
  	
  end
  
end

================================================
FILE: lib/examples/spectra_soft_pot.rb
================================================
class SpectraSoftPot < ArduinoSketch

  # demonstrate capability to use soft pot as traditional pot
  # the last pot reading remains "locked" to the last touch point
  # similar same behavior as ipod
  #
  # this sketch assumes a pa_lcd operating at 19200 and one 
  # spectra symbol softpot connected to analog pin 3
  # 

  output_pin 5, :as => :my_lcd, :device => :pa_lcd, :rate => 19200, :clear_screen => :true
  input_pin 3, :as => :sensor_one, :device => :spectra


   def setup
     delay 1000
     my_lcd.setxy 0,0, "spectra symbol"
     my_lcd.setxy 0,1, "soft pot"
     delay 5000
     my_lcd.clearscr
   end

   def loop
     my_lcd.setxy 0,1
     # since lcd's have issues clearing tens and hundreds digits when reading ones, 
     # we use pad_int_to_str, which is a hack to display these cleanly
     # pad_int_to_str takes two arguments: an integer and the final string length
     # 
     my_lcd.print pad_int_to_str sensor_one.soft_lock, 3
     delay 100
   end
    

end

================================================
FILE: lib/examples/times_method.rb
================================================
class TimesMethod < ArduinoSketch

  def loop
    5.times { delay 200 }
  end

  
end

================================================
FILE: lib/examples/toggle.rb
================================================
class Toggle < ArduinoSketch

    output_pin 13, :as => :led

       def loop
         led.toggle
         delay 300
       end

  end

================================================
FILE: lib/examples/twitter.rb
================================================
class Twitter < ArduinoSketch
  
  #include <avr/io.h>
  #include <string.h>



  define "TWEETLEN 141"
  define "HOSTNAME www.twitter.com"
  
  define 'IPADDR "128.121.146.100"'  # twitter.com
  define "PORT 80"                 # // HTTP
  define "HTTPPATH /atduskgreg/"    # // the person we want to follow
  

  define "TWEETLEN 141"
  array "char linebuffer[256]" # // our large buffer for data
  array "char tweet[TWEETLEN]" # // the tweet
  @lines = 0

  
  define "XPORT_RXPIN 2"
  define "XPORT_TXPIN 3"
  define "XPORT_RESETPIN 4"
  define "XPORT_DTRPIN 5"
  define "XPORT_CTSPIN 6"
  define "XPORT_RTSPIN 7"
  

  @errno = 0
  @laststatus = 0
  @currstatus = 0


  
# in setup
#xport = AF_XPort(XPORT_RX, XPORT_TX, XPORT_RESET, XPORT_DTR, XPORT_RTS, XPORT_CTS)
  
  
  output_pin 10, :as => :shield, :device => :ethernet
  
  serial_begin :rate => 57600
  
  def loop
    
#  local_connect()
    # kind of a problem... fixed
    get_tweet
    fetchtweet
    delay 30000


  end
  

  
end

================================================
FILE: lib/examples/two_wire.rb
================================================
class TwoWire < ArduinoSketch

  # just a demo that two_wire loads

  output_pin 19, :as => :wire, :device => :i2c, :enable => :true
  
  def loop

	  x = 4    
  
  end
    

end

================================================
FILE: lib/libraries/Wire/utility/twi.c
================================================
/*
  twi.c - TWI/I2C library for Wiring & Arduino
  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <math.h>
#include <stdlib.h>
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <compat/twi.h>

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#include "twi.h"

static volatile uint8_t twi_state;
static uint8_t twi_slarw;

static void (*twi_onSlaveTransmit)(void);
static void (*twi_onSlaveReceive)(uint8_t*, int);

static uint8_t* twi_masterBuffer;
static volatile uint8_t twi_masterBufferIndex;
static uint8_t twi_masterBufferLength;

static uint8_t* twi_txBuffer;
static volatile uint8_t twi_txBufferIndex;
static volatile uint8_t twi_txBufferLength;

static uint8_t* twi_rxBuffer;
static volatile uint8_t twi_rxBufferIndex;

/* 
 * Function twi_init
 * Desc     readys twi pins and sets twi bitrate
 * Input    none
 * Output   none
 */
void twi_init(void)
{
  // initialize state
  twi_state = TWI_READY;

  #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega8__)
    // activate internal pull-ups for twi
    // as per note from atmega8 manual pg167
    sbi(PORTC, 4);
    sbi(PORTC, 5);
  #else
    // activate internal pull-ups for twi
    // as per note from atmega128 manual pg204
    sbi(PORTD, 0);
    sbi(PORTD, 1);
  #endif

  // initialize twi prescaler and bit rate
  cbi(TWSR, TWPS0);
  cbi(TWSR, TWPS1);
  TWBR = ((CPU_FREQ / TWI_FREQ) - 16) / 2;

  /* twi bit rate formula from atmega128 manual pg 204
  SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
  note: TWBR should be 10 or higher for master mode
  It is 72 for a 16mhz Wiring board with 100kHz TWI */

  // enable twi module, acks, and twi interrupt
	TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
	
	// allocate buffers
  twi_masterBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
  twi_txBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
  twi_rxBuffer = (uint8_t*) calloc(TWI_BUFFER_LENGTH, sizeof(uint8_t));
}

/* 
 * Function twi_slaveInit
 * Desc     sets slave address and enables interrupt
 * Input    none
 * Output   none
 */
void twi_setAddress(uint8_t address)
{
  // set twi slave address (skip over TWGCE bit)
  TWAR = address << 1;
}

/* 
 * Function twi_readFrom
 * Desc     attempts to become twi bus master and read a
 *          series of bytes from a device on the bus
 * Input    address: 7bit i2c device address
 *          data: pointer to byte array
 *          length: number of bytes to read into array
 * Output   byte: 0 ok, 1 length too long for buffer
 */
uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length)
{
  uint8_t i;

  // ensure data will fit into buffer
  if(TWI_BUFFER_LENGTH < length){
    return 1;
  }

  // wait until twi is ready, become master receiver
  while(TWI_READY != twi_state){
    continue;
  }
  twi_state = TWI_MRX;

  // initialize buffer iteration vars
  twi_masterBufferIndex = 0;
  twi_masterBufferLength = length;

  // build sla+w, slave device address + w bit
  twi_slarw = TW_READ;
	twi_slarw |= address << 1;

  // send start condition
	TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);

	// wait for read operation to complete
	while(TWI_MRX == twi_state){
	  continue;
	}

  // copy twi buffer to data
  for(i = 0; i < length; ++i){
    data[i] = twi_masterBuffer[i];
  }
	
	return 0;
}

/* 
 * Function twi_writeTo
 * Desc     attempts to become twi bus master and write a
 *          series of bytes to a device on the bus
 * Input    address: 7bit i2c device address
 *          data: pointer to byte array
 *          length: number of bytes in array
 *          wait: boolean indicating to wait for write or not
 * Output   byte: 0 ok, 1 length too long for buffer
 */
uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait)
{
  uint8_t i;

  // ensure data will fit into buffer
  if(TWI_BUFFER_LENGTH < length){
    return 1;
  }

  // wait until twi is ready, become master transmitter
  while(TWI_READY != twi_state){
    continue;
  }
  twi_state = TWI_MTX;

  // initialize buffer iteration vars
  twi_masterBufferIndex = 0;
  twi_masterBufferLength = length;
  
  // copy data to twi buffer
  for(i = 0; i < length; ++i){
    twi_masterBuffer[i] = data[i];
  }
  
  // build sla+w, slave device address + w bit
  twi_slarw = TW_WRITE;
	twi_slarw |= address << 1;
  
  // send start condition
	TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTA);

	// wait for write operation to complete
	while(wait && (TWI_MTX == twi_state)){
	  continue;
	}
	
	return 0;
}

/* 
 * Function twi_transmit
 * Desc     fills slave tx buffer with data
 *          must be called in slave tx event callback
 * Input    data: pointer to byte array
 *          length: number of bytes in array
 * Output   1 length too long for buffer
 *          2 not slave transmitter
 *          0 ok
 */
uint8_t twi_transmit(uint8_t* data, uint8_t length)
{
  uint8_t i;

  // ensure data will fit into buffer
  if(TWI_BUFFER_LENGTH < length){
    return 1;
  }
  
  // ensure we are currently a slave transmitter
  if(TWI_STX != twi_state){
    return 2;
  }
  
  // set length and copy data into tx buffer
  twi_txBufferLength = length;
  for(i = 0; i < length; ++i){
    twi_txBuffer[i] = data[i];
  }
  
  return 0;
}

/* 
 * Function twi_attachSlaveRxEvent
 * Desc     sets function called before a slave read operation
 * Input    function: callback function to use
 * Output   none
 */
void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) )
{
  twi_onSlaveReceive = function;
}

/* 
 * Function twi_attachSlaveTxEvent
 * Desc     sets function called before a slave write operation
 * Input    function: callback function to use
 * Output   none
 */
void twi_attachSlaveTxEvent( void (*function)(void) )
{
  twi_onSlaveTransmit = function;
}

/* 
 * Function twi_reply
 * Desc     sends byte or readys receive line
 * Input    ack: byte indicating to ack or to nack
 * Output   none
 */
void twi_reply(uint8_t ack)
{
	// transmit master read ready signal, with or without ack
	if(ack){
	  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);
  }else{
	  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT);
  }
}

/* 
 * Function twi_stop
 * Desc     relinquishes bus master status
 * Input    none
 * Output   none
 */
void twi_stop(void)
{
  // send stop condition
  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO);

  // wait for stop condition to be exectued on bus
  // TWINT is not set after a stop condition!
  while(TWCR & _BV(TWSTO)){
    continue;
  }

  // update twi state
  twi_state = TWI_READY;
}

/* 
 * Function twi_releaseBus
 * Desc     releases bus control
 * Input    none
 * Output   none
 */
void twi_releaseBus(void)
{
  // release bus
  TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT);

  // update twi state
  twi_state = TWI_READY;
}

SIGNAL(SIG_2WIRE_SERIAL)
{
  switch(TW_STATUS){
    // All Master
    case TW_START:     // sent start condition
    case TW_REP_START: // sent repeated start condition
      // copy device address and r/w bit to output register and ack
      TWDR = twi_slarw;
      twi_reply(1);
      break;

    // Master Transmitter
    case TW_MT_SLA_ACK:  // slave receiver acked address
    case TW_MT_DATA_ACK: // slave receiver acked data
      // if there is data to send, send it, otherwise stop 
      if(twi_masterBufferIndex < twi_masterBufferLength){
        // copy data to output register and ack
        TWDR = twi_masterBuffer[twi_masterBufferIndex++];
        twi_reply(1);
      }else{
        twi_stop();
      }
      break;
    case TW_MT_SLA_NACK:  // address sent, nack received
    case TW_MT_DATA_NACK: // data sent, nack received
      twi_stop();
      break;
    case TW_MT_ARB_LOST: // lost bus arbitration
      twi_releaseBus();
      break;

    // Master Receiver
    case TW_MR_DATA_ACK: // data received, ack sent
      // put byte into buffer
      twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
    case TW_MR_SLA_ACK:  // address sent, ack received
      // ack if more bytes are expected, otherwise nack
      if(twi_masterBufferIndex < twi_masterBufferLength){
        twi_reply(1);
      }else{
        twi_reply(0);
      }
      break;
    case TW_MR_DATA_NACK: // data received, nack sent
      // put final byte into buffer
      twi_masterBuffer[twi_masterBufferIndex++] = TWDR;
    case TW_MR_SLA_NACK: // address sent, nack received
      twi_stop();
      break;
    // TW_MR_ARB_LOST handled by TW_MT_ARB_LOST case

    // Slave Receiver
    case TW_SR_SLA_ACK:   // addressed, returned ack
    case TW_SR_GCALL_ACK: // addressed generally, returned ack
    case TW_SR_ARB_LOST_SLA_ACK:   // lost arbitration, returned ack
    case TW_SR_ARB_LOST_GCALL_ACK: // lost arbitration, returned ack
      // enter slave receiver mode
      twi_state = TWI_SRX;
      // indicate that rx buffer can be overwritten and ack
      twi_rxBufferIndex = 0;
      twi_reply(1);
      break;
    case TW_SR_DATA_ACK:       // data received, returned ack
    case TW_SR_GCALL_DATA_ACK: // data received generally, returned ack
      // if there is still room in the rx buffer
      if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
        // put byte in buffer and ack
        twi_rxBuffer[twi_rxBufferIndex++] = TWDR;
        twi_reply(1);
      }else{
        // otherwise nack
        twi_reply(0);
      }
      break;
    case TW_SR_STOP: // stop or repeated start condition received
      // put a null char after data if there's room
      if(twi_rxBufferIndex < TWI_BUFFER_LENGTH){
        twi_rxBuffer[twi_rxBufferIndex] = '\0';
      }
      // callback to user defined callback
      twi_onSlaveReceive(twi_rxBuffer, twi_rxBufferIndex);
      // ack future responses
      twi_reply(1);
      // leave slave receiver state
      twi_state = TWI_READY;
      break;
    case TW_SR_DATA_NACK:       // data received, returned nack
    case TW_SR_GCALL_DATA_NACK: // data received generally, returned nack
      // nack back at master
      twi_reply(0);
      break;
    
    // Slave Transmitter
    case TW_ST_SLA_ACK:          // addressed, returned ack
    case TW_ST_ARB_LOST_SLA_ACK: // arbitration lost, returned ack
      // enter slave transmitter mode
      twi_state = TWI_STX;
      // ready the tx buffer index for iteration
      twi_txBufferIndex = 0;
      // set tx buffer length to be zero, to verify if user changes it
      twi_txBufferLength = 0;
      // request for txBuffer to be filled and length to be set
      // note: user must call twi_transmit(bytes, length) to do this
      twi_onSlaveTransmit();
      // if they didn't change buffer & length, initialize it
      if(0 == twi_txBufferLength){
        twi_txBufferLength = 1;
        twi_txBuffer[0] = 0x00;
      }
      // transmit first byte from buffer, fall
    case TW_ST_DATA_ACK: // byte sent, ack returned
      // copy data to output register
      TWDR = twi_txBuffer[twi_txBufferIndex++];
      // if there is more to send, ack, otherwise nack
      if(twi_txBufferIndex < twi_txBufferLength){
        twi_reply(1);
      }else{
        twi_reply(0);
      }
      break;
    case TW_ST_DATA_NACK: // received nack, we are done 
    case TW_ST_LAST_DATA: // received ack, but we are done already!
      // ack future responses
      twi_reply(1);
      // leave slave receiver state
      twi_state = TWI_READY;
      break;

    // All
    case TW_NO_INFO:   // no state information
      break;
    case TW_BUS_ERROR: // bus error, illegal stop/start
      twi_stop();
      break;
  }
}



================================================
FILE: lib/libraries/Wire/utility/twi.h
================================================
/*
  twi.h - TWI/I2C library for Wiring & Arduino
  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef twi_h
#define twi_h

  #include <inttypes.h>

  //#define ATMEGA8

  #ifndef CPU_FREQ
  #define CPU_FREQ 16000000L
  #endif

  #ifndef TWI_FREQ
  #define TWI_FREQ 100000L
  #endif

  #ifndef TWI_BUFFER_LENGTH
  #define TWI_BUFFER_LENGTH 32
  #endif

  #define TWI_READY 0
  #define TWI_MRX   1
  #define TWI_MTX   2
  #define TWI_SRX   3
  #define TWI_STX   4
  
  void twi_init(void);
  void twi_setAddress(uint8_t);
  uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t);
  uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t);
  uint8_t twi_transmit(uint8_t*, uint8_t);
  void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) );
  void twi_attachSlaveTxEvent( void (*)(void) );
  void twi_reply(uint8_t);
  void twi_stop(void);
  void twi_releaseBus(void);

#endif



================================================
FILE: lib/plugins/bitwise_ops.rb
================================================
class BitwiseOps < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)


  # add to directives
 
  # add to external variables
 
  # add the following to the setup method
  # add_to_setup 


int build_int(int hibyte, int lobyte) {
    return((hibyte << 8) + lobyte);
}

int i_shiftleft(int val, int shift) {
    return(val << shift);
}

int i_shiftright(int val, int shift) {
    return(val >> shift);
}

byte b_shiftleft(byte val, byte shift) {
    return(val << shift);
}

byte b_shiftright(byte val, byte shift) {
    return(val >> shift);
}

int bit_and(int val, int mask) {
    return(val & mask);
}

int bit_or(int val, int mask) {
    return(val | mask);
}

int bit_xor(int val, int mask) {
    return(val ^ mask);
}

int twos_comp(int val) {
    return((val ^ 0xffff) + 1);
}

end

================================================
FILE: lib/plugins/blink.rb
================================================
class Blink < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)


  # add to directives
 
  # add to external variables
 
  # add the following to the setup method
  # add_to_setup 


  void blink(int pin, int ms) {
  	digitalWrite( pin, HIGH );
  	delay( ms );
  	digitalWrite( pin, LOW );
  	delay( ms );
  }

end

================================================
FILE: lib/plugins/blink_m.rb
================================================
class BlinkM < ArduinoPlugin

#
#
#  BlinkM_funcs.h -- Arduino library to control BlinkM
#  --------------
#
#
#  Note: original version of this file lives with the BlinkMTester sketch
#
#  2007, Tod E. Kurt, ThingM, http://thingm.com/
#
#  version: 20080203
#
#  history:
#   20080101 - initial release
#   20080203 - added setStartupParam(), bugfix receiveBytes() from Dan Julio
#   20080727 - ported to rad jd barnhart
#
#   first step, declare output pin 19 as i2c
##  output_pin 19, :as => :wire, :device => :i2c, :enable => :true # reminder, true issues wire.begin


include_wire

add_blink_m_struct



# Not needed when pin is declared with :enable => :true 
# In fact, declaring it twice causes nothing but problems

static void BlinkM_begin()
{
    Wire.begin();                // join i2c bus (address optional for master)
}


// General version of BlinkM_beginWithPower().

static void BlinkM_beginWithPowerPins(byte pwrpin, byte gndpin)
{
    DDRC |= _BV(pwrpin) | _BV(gndpin);  // make outputs
    PORTC &=~ _BV(gndpin);
    PORTC |=  _BV(pwrpin);
    delay(100);  // wait for things to stabilize

    Wire.begin();
}

// Call this first when BlinkM is plugged directly into Arduino
// The BlinkMs PWR (power) pins should line up with pins 2 and 3 of the connector, 
// while the I2C (communications) pins should line up with pins 4 and 5.

static void BlinkM_beginWithPower()
{
    BlinkM_beginWithPowerPins( PC3, PC2 );
}

// sends a generic command

static void BlinkM_sendCmd(byte addr, byte* cmd, int cmdlen)
{
    Wire.beginTransmission(addr);
    for( byte i=0; i<cmdlen; i++) 
        Wire.send(cmd[i]);
    Wire.endTransmission();
}

// receives generic data
// returns 0 on success, and -1 if no data available
// note: responsiblity of caller to know how many bytes to expect

static int BlinkM_receiveBytes(byte addr, byte* resp, byte len)
{
    Wire.requestFrom(addr, len);
    if( Wire.available() ) {
        for( int i=0; i<len; i++) 
            resp[i] = Wire.receive();
        return 0;
    }
    return -1;
}

// Sets the I2C address of the BlinkM(s)
// Typically used to setup BlinkM addresses
// Connect one and call this with an address like 10, 
// then 11 for the next and so on and so forth 
// Uses "general call" broadcast address

static void BlinkM_setAddress(byte newaddress)
{
  Wire.beginTransmission(0x00);  // general call (broadcast address)
  Wire.send('A');
  Wire.send(newaddress);
  Wire.send(0xD0);
  Wire.send(0x0D);  // dood!
  Wire.send(newaddress);
  Wire.endTransmission();
  delay(50); // just in case
}


// Gets the I2C addrss of the BlinkM
// Kind of redundant when sent to a specific address
// but uses to verify BlinkM communication

static int BlinkM_getAddress(byte addr)
{
    Wire.beginTransmission(addr);
    Wire.send('a');
    Wire.endTransmission();
    Wire.requestFrom(addr, (byte)1);
    if( Wire.available() ) {
        byte b = Wire.receive();
        return b; 
    }
    return -1;
}

// Gets the BlinkM firmware version

static int BlinkM_getVersion(byte addr)
{
    Wire.beginTransmission(addr);
    Wire.send('Z');
    Wire.endTransmission();
    Wire.requestFrom(addr, (byte)2);
    if( Wire.available() ) {
        byte major_ver = Wire.receive();
        byte minor_ver = Wire.receive();
        return (major_ver<<8) + minor_ver;
    }
    return -1;
}

// Demonstrates how to verify you-re talking to a BlinkM 
// and that you know its address -- message version

static char* blink_m_check_address_message(byte addr) // :as => :optional
{
    char message[50];
    char status[5];
    strcpy(message, "received 0x");
    //Serial.print("Checking BlinkM address...");
    int b = BlinkM_getAddress(addr);
    if( b==-1 ) {
        //Serial.println("No response, that's not good");
        return "No response, that's not good";  // no response
    } 
    itoa(b, status ,16);
    
    //Serial.print("received addr: 0x");
    //Serial.print(b,HEX);
    if( b != addr )
        return "error, mismatch"; // error, addr mismatch 
    else 
        return strcat(message, status); // match, everything okay
}

// Demonstrates how to verify you-re talking to a BlinkM 
// and that you know its address -- digital version

static int BlinkM_checkAddress(byte addr)
{
    //Serial.print("Checking BlinkM address...");
    int b = BlinkM_getAddress(addr);
    if( b==-1 ) {
        //Serial.println("No response, that's not good");
        return -1;  // no response
    } 
    
    //Serial.print("received addr: 0x");
    //Serial.print(b,HEX);
    if( b != addr )
        return 1; // error, addr mismatch 
    else 
        return 0; // match, everything okay
}

// Sets the speed of fading between colors.  
// Higher numbers means faster fading, 255 == instantaneous fading

static void BlinkM_setFadeSpeed(byte addr, byte fadespeed)
{
    Wire.beginTransmission(addr);
    Wire.send('f');
    Wire.send(fadespeed);
    Wire.endTransmission();  
}

// Sets the light script playback time adjust
// The timeadj argument is signed, and is an additive value to all
// durations in a light script. Set to zero to turn off time adjust.

static void BlinkM_setTimeAdj(byte addr, byte timeadj)
{
    Wire.beginTransmission(addr);
    Wire.send('t');
    Wire.send(timeadj);
    Wire.endTransmission();  
}

// Fades to an RGB color

static void BlinkM_fadeToRGB(byte addr, byte red, byte grn, byte blu)
{
    Wire.beginTransmission(addr);
    Wire.send('c');
    Wire.send(red);
    Wire.send(grn);
    Wire.send(blu);
    Wire.endTransmission();
}

// Fades to an HSB color

static void BlinkM_fadeToHSB(byte addr, byte hue, byte saturation, byte brightness)
{
    Wire.beginTransmission(addr);
    Wire.send('h');
    Wire.send(hue);
    Wire.send(saturation);
    Wire.send(brightness);
    Wire.endTransmission();
}

// Sets an RGB color immediately

static void BlinkM_setRGB(byte addr, byte red, byte grn, byte blu)
{
    Wire.beginTransmission(addr);
    Wire.send('n');
    Wire.send(red);
    Wire.send(grn);
    Wire.send(blu);
    Wire.endTransmission();
}

// Fades to a random RGB color

static void BlinkM_fadeToRandomRGB(byte addr, byte rrnd, byte grnd, byte brnd)
{
    Wire.beginTransmission(addr);
    Wire.send('C');
    Wire.send(rrnd);
    Wire.send(grnd);
    Wire.send(brnd);
    Wire.endTransmission();
}
// Fades to a random HSB color

static void BlinkM_fadeToRandomHSB(byte addr, byte hrnd, byte srnd, byte brnd)
{
    Wire.beginTransmission(addr);
    Wire.send('H');
    Wire.send(hrnd);
    Wire.send(srnd);
    Wire.send(brnd);
    Wire.endTransmission();
}

static void BlinkM_getRGBColor(byte addr, byte* r, byte* g, byte* b)
{
    Wire.beginTransmission(addr);
    Wire.send('g');
    Wire.endTransmission();
    Wire.requestFrom(addr, (byte)3);
    if( Wire.available() ) {
        *r = Wire.receive();
        *g = Wire.receive();
        *b = Wire.receive();
    }
}

static void BlinkM_playScript(byte addr, byte script_id, byte reps, byte pos)
{
    Wire.beginTransmission(addr);
    Wire.send('p');
    Wire.send(script_id);
    Wire.send(reps);
    Wire.send(pos);
    Wire.endTransmission();
}

static void BlinkM_stopScript(byte addr)
{
    Wire.beginTransmission(addr);
    Wire.send('o');
    Wire.endTransmission();
}

static void BlinkM_setScriptLengthReps(byte addr, byte script_id, 
                                       byte len, byte reps)
{
    Wire.beginTransmission(addr);
    Wire.send('L');
    Wire.send(script_id);
    Wire.send(len);
    Wire.send(reps);
    Wire.endTransmission();
}

static void BlinkM_writeScriptLine(byte addr, byte script_id, 
                                   byte pos, byte dur,
                                   byte cmd, byte arg1, byte arg2, byte arg3)
{
#ifdef BLINKM_FUNCS_DEBUG
    Serial.print("writing line:");  Serial.print(pos,DEC);
    Serial.print(" with cmd:"); Serial.print(cmd); 
    Serial.print(" arg1:"); Serial.println(arg1,HEX);
#endif
    Wire.beginTransmission(addr);
    Wire.send('W');
    Wire.send(script_id);
    Wire.send(pos);
    Wire.send(dur);
    Wire.send(cmd);
    Wire.send(arg1);
    Wire.send(arg2);
    Wire.send(arg3);
    Wire.endTransmission();
}

static void BlinkM_writeScript(byte addr, byte script_id, 
                               byte len, byte reps,
                               blinkm_script_line* lines)
{
#ifdef BLINKM_FUNCS_DEBUG
    Serial.print("writing script to addr:"); Serial.print(addr,DEC);
    Serial.print(", script_id:"); Serial.println(script_id,DEC);
#endif
    for(byte i=0; i < len; i++) {
        blinkm_script_line l = lines[i];
        BlinkM_writeScriptLine( addr, script_id, i, l.dur,
                                l.cmd[0], l.cmd[1], l.cmd[2], l.cmd[3]);
    }
    BlinkM_setScriptLengthReps(addr, script_id, len, reps);
}


static void BlinkM_setStartupParams(byte addr, byte mode, byte script_id,
                                    byte reps, byte fadespeed, byte timeadj)
{
    Wire.beginTransmission(addr);
    Wire.send('B');
    Wire.send(mode);
    Wire.send(script_id);
    Wire.send(reps);
    Wire.send(fadespeed);
    Wire.send(timeadj);
    Wire.endTransmission();
} 


end

================================================
FILE: lib/plugins/debounce.rb
================================================
class Debounce < ArduinoPlugin
  

  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)
  # hack from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209050315

  # plugin_directives "#undef int", "#include <stdio.h>", "char _str[32];", "#define writeln(...) sprintf(_str, __VA_ARGS__); Serial.println(_str)"
  # add to directives
  #plugin_directives "#define EXAMPLE 10"

  # add to external variables
  # ok, we need to deal with 
  # what about variables 
  # need to loose the colon...
  # external_variables "char status_message[40] = \"very cool\"", "char* msg[40]"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are generated automatically with rake make:upload
  
# call pulse(us) to pulse a servo 

#####################

## How this works

##  The cast:
##   a normally open push button (circuit is closed when button is depressed)
##    variables [input].
##    [input]read: or current read -- what we see from the input pin HIGH (1) untouched or LOW (1) depressed
##    [input]prev: or previous read – assigned to current reading at the end of the method
##    [input]state: the stored state HIGH (1) or LOW (0)
##    [input]time: the time when we last had a true
##    millis: number of milliseconds since the Arduino began running the current program

## So….

##    If HIGH and the [input]read was LOW (button was depressed since the last time we looped) AND If millis() - [input]time  > 200
##    Flip the state
##    And assign [input]time millis()
##    Else Set the pin to [input]state 
##    Assign [input]prev to [input]read

## abstract summary:

##    So 99%+ of the time, we always see a HIGH (unless the button is pushed)
##    If the button is pushed, we record this LOW to [input]prev, so the next time we enter the loop and the button is not being pushed we see true as long as millis() minus the [input]time of the last toggle is greater the 200 (adjust, which can be set with an adjust option)


######################


add_debounce_struct

# increase the debounce_setting, increase if the output flickers 
# need docs..
# and testing
#
# remember these are being called from the loop (typically)
# 
# NOTE: if two buttons are controlling one output, today, strange
#       things will happen since each button tries to assert its own state
#       suggestion: we can fix this with an array of structs for shared outputs
#       ie: output_pin 5, :as => :yellow_led, :shared => :yes # default no
#       this would put the state at the output which could be compared to 
#       the inputs_state and override and set it if different



int toggle(int output)
{
  return toggle_output(output);
}

int toggle_output(int output)
{
  if (dbce[output].state == HIGH)
    dbce[output].state = LOW;
  else
    dbce[output].state = HIGH;
    digitalWrite(output, dbce[output].state);

    return dbce[output].state;
}


int read_input(int input)
{
  int state = LOW;
  dbce[input].read = digitalRead(input);

  if (dbce[input].read == HIGH && dbce[input].prev == LOW && millis() - dbce[input].time > dbce[input].adjust)
     {
      dbce[input].time = millis();
      state = HIGH;
    }
  else 
    state = LOW;
    
      dbce[input].prev = dbce[input].read;
      return state;
}


int toggle(int input, int output)
{
  return read_and_toggle(input, output);
}

int read_and_toggle(int input, int output)
{
  dbce[input].read = digitalRead(input);
  // did we just release a button which was depressed the last time we checked and over 200 millseconds has passed since this statement was last true?
  if (dbce[input].read == HIGH && dbce[input].prev == LOW && millis() - dbce[input].time > dbce[input].adjust) {
    // ... flip the output
    if (dbce[input].state == HIGH)
      dbce[input].state = LOW;
    else
      dbce[input].state = HIGH;

    /* save time of last press */
    dbce[input].time = millis();    
  }

  digitalWrite(output, dbce[input].state);

  dbce[input].prev = dbce[input].read;
  
  return dbce[input].state; 
}

    
end

================================================
FILE: lib/plugins/debug_output_to_lcd.rb
================================================
class DebugOutputToLcd < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

# add to directives
#plugin_directives "#define ARY_SIZE 10"
  
# add to external variables
#external_variables "unsigned long start_loop_time = 0;", "unsigned long total_loop_time = 0;"

# add the following to the setup method
#add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"

# add an element to the array and return the average

# need a nice home for these





void send_servo_debug_to_lcd(int servo)
{
  lcd_first_line();
  Serial.print("pw ");
  Serial.print( find_servo_pulse_width(servo));
  Serial.print(" lp ");
  Serial.print( find_servo_last_pulse(servo));
  Serial.print("s");
  Serial.print( find_servo_start_pulse(servo));
//  Serial.print(" t");
//  Serial.print( find_debounce_time(servo));

  lcd_second_line();
  Serial.print("d");
//  Serial.print( millis() - find_debounce_time(servo));
  Serial.print(" m");
  Serial.print(millis());
  
}


void send_button_debug_to_lcd(int button)
{
  
  lcd_first_line();
  Serial.print("r");
  Serial.print( find_debounce_read(button));
  Serial.print("p");
  Serial.print( find_debounce_prev(button));
  Serial.print("s");
  Serial.print( find_debounce_state(button));
  Serial.print(" t");
  Serial.print( find_debounce_time(button));

  lcd_second_line();
  Serial.print("d");
  Serial.print( millis() - find_debounce_time(button));
  Serial.print(" m");
  Serial.print(millis());
  
}




end

================================================
FILE: lib/plugins/hysteresis.rb
================================================
class Hysteresis < ArduinoPlugin
  
# jdbarnhart
# 20080728
#
#
# purpose
#
# add hysteresis to analog readings, typically sensors or potentiometers
#
# use
# two steps
#
#  one
#    declare :device => :sensor 
#    example:
#      input_pin 1, :as => :sensor_one, :device => :sensor
#
#  two
#    instead of:
#      my_lcd.print analogRead sensor_two
#      use add_hyst
#      my_lcd.print sensor_one.with_hyst 4
#      
#      # note, 4 is the amount of hysteresis
#
#
void with_hysteresis(int pin, int amt)
{
  with_hyst(pin, amt);
}

int with_hyst(int pin, int amt)
{
  int read;
  unsigned int i;
  read = analogRead(pin);
  for (i = 0; i < (int) (sizeof(hyst) / sizeof(hyst[0])); i++) {   
    if (pin == hyst[i].pin) {
      if (((read - hyst[i].state) > amt ) || ((hyst[i].state - read) > amt )) {
        hyst[i].state = read;
        return hyst[i].state;
      } 
      else
        return hyst[i].state;      
    }
  }
}



end

================================================
FILE: lib/plugins/input_output_state.rb
================================================
class InputOutputState < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

# add to directives
#plugin_directives "#define ARY_SIZE 10"
  
# add to external variables
#external_variables "int *cur, *scan, *start, *end;", "int sm_ary[ARY_SIZE];"

# add the following to the setup method
#add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"

# return states of button and servo output stored in 
# array structs dbcd (debounce) and serv (servo)
# need error catch ...
# how about auto generating documentation from plugins
# at least showing 



int find_debounce_state(int input)
{
return dbce[input].state;
}

int find_debounce_read(int input)
{
return dbce[input].read;
}

int find_debounce_prev(int input)
{
return dbce[input].prev;
}

unsigned long find_debounce_time(int input)
{
return dbce[input].time;
}

int find_debounce_adjust(int input)
{
return dbce[input].adjust;
}

long unsigned find_servo_pulse_width(int input)
{
return serv[input].pulseWidth;
}

unsigned long find_servo_last_pulse(int input)
{
return serv[input].lastPulse;
}

unsigned long find_servo_start_pulse(int input)
{
return serv[input].startPulse;

}

unsigned long find_servo_refresh_time(int input)
{
return serv[input].refreshTime;
}

int find_servo_min(int input)
{
return serv[input].min;
}

int find_servo_max(int input)
{
return serv[input].max;

}


end

================================================
FILE: lib/plugins/lcd_padding.rb
================================================
class LCDPadding < ArduinoPlugin
  
# jdbarnhart
# 20080729
#
#
# purpose

# simple integer padding for lcd display pad
#
# example
# my_lcd.print pad_int_to_str 29, 5
# 
# result
# "   29"
  


static char* pad_int_to_str(int num, int length) 
{
    int i = 0;
    int start;
    char plain[20];
    char space[5] = "  ";
    char* pretty = "        ";    
    itoa(num, plain ,10);
    start = length - strlen(plain);
    while (i <= length) {
      if (i >= start)
        pretty[i] = plain[i - start];       
      else
        pretty[i] = space[0];
      i++;
    }
    return pretty;
}

static char* pad_int_to_str_w_zeros(int num, int length) 
{
    int i = 0;
    int start;
    char plain[20];
    char space[5] = "0 ";    
    char* pretty = "        ";    
    itoa(num, plain ,10);
    start = length - strlen(plain);
    while (i <= length) {
      if (i >= start)
        pretty[i] = plain[i - start];       
      else
        pretty[i] = space[0];
      i++;
    }
    return pretty;
}


end

================================================
FILE: lib/plugins/mem_test.rb
================================================
class MemTest < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

  # add to directives
  #plugin_directives "#define EXAMPLE 10"

  # add to external variables
  # external_variables "int foo, bar"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are generated automatically with rake make:upload
  
  # test the memory on your arduino uncommenting the following:
  # add_to_setup "memoryTest();"
  # or adding "memoryTest()" (no semicolon) to your main sketch

int memoryTest() {
  int byteCounter = 0; // initialize a counter
  byte *byteArray; // create a pointer to a byte array
  while ( (byteArray = (byte*) malloc (byteCounter * sizeof(byte))) != NULL ) {
   byteCounter++; // if allocation was successful, then up the count for the next try
    free(byteArray); // free memory after allocating it
 }

 free(byteArray); // also free memory after the function finishes"
 return byteCounter; // send back the highest number of bytes successfully allocated
}


end

================================================
FILE: lib/plugins/midi.rb
================================================
class Midi < ArduinoPlugin
 
 
# reference 
  
# To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino.
# DIN-5 pinout is:                               _____ 
#    pin 2 - Gnd                                /     \
#    pin 4 - 220 ohm resistor to +5V           | 3   1 |  Female MIDI jack 
#    pin 5 - Arduino D1 (TX)                   |  5 4  |
#    all other pins - unconnected               \__2__/
#  Adapted from Tom Igoe's work at:
#   http://itp.nyu.edu/physcomp/Labs/MIDIOutput
#  And Tod E. Kurt <tod@todbot.com
#   http://todbot.com/
#
#  Created 25 October 2008
#  copyleft 2008 jdbarnhart 
#  http://jdbarnhart.com/
  
void note_on(char cmd, int data1, char data2) {
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
}
  
void note_on(int channel, int note, int velocity) {
  midi_msg( (0x90 | (channel)), note, velocity);
}

void note_on(long int& channel, long int& note, long int& velocity) {
  midi_msg( (0x90 | (channel)), note, velocity);
}

void note_off(long int& channel, long int& note, long int& velocity) {
  midi_msg( (0x90 | (channel)), note, velocity);
}

void note_off(byte channel, byte note, byte velocity) {
  midi_msg( (0x90 | (channel)), note, velocity);
}

void play_note(long int& channel, long int& note, long int& velocity) {
  midi_msg( (0x90 | (channel)), note, velocity);
  delay(100);
  midi_msg( (0x90 | (channel)), note, 0);
}



void midi_msg(byte cmd, byte data1, byte data2) {
  digitalWrite(led(), 1); // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  digitalWrite(led(), 0); // indicate we're sending MIDI data
}


end

================================================
FILE: lib/plugins/parallax_ping.rb
================================================
class ParallaxPing < ArduinoPlugin

  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

  # add to directives
  # plugin_directives "#define EXAMPLE 10"

  # add to external variables
  # external_variables "int foo, bar"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are
  
  # Methods for the Parallax Ping)) UltraSonic Distance Sensor.
  # 
  # Example:
  #
  # class RangeFinder < ArduinoSketch
  #   serial_begin
  #   
  #   external_vars :sig_pin => 'int, 7'
  #   
  #   def loop
  #     serial_println(ping(sig_pin)) 
  #     delay(200) 
  #   end
  # end

  # Triggers a pulse and returns the delay in microseconds for the echo.
  int ping(int pin) {
    pinMode(pin, OUTPUT);

    digitalWrite(pin, LOW);
    delayMicroseconds(2);
    digitalWrite(pin, HIGH);
    delayMicroseconds(5);
    digitalWrite(pin, LOW);

    pinMode(pin, INPUT);

    return pulseIn(pin, HIGH);
  }

end

================================================
FILE: lib/plugins/servo_pulse.rb
================================================
class ServoPulse < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

  # add to directives
  #plugin_directives "#define EXAMPLE 10"

  # add to external variables
  # external_variables "int foo, bar"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are generated automatically with rake make:upload
  
# call pulse(us) to pulse a servo  
# this can be eliminate since we have an identical pulse_servo in servo_setup

void pulse(int pin, int us) {
  digitalWrite( pin, HIGH );
  delayMicroseconds( us );
  digitalWrite( pin, LOW );
  serv[pin].pulseWidth = us;
}
    

end

================================================
FILE: lib/plugins/servo_setup.rb
================================================
class ServoSetup < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

  # add to directives
  #plugin_directives "#define EXAMPLE 10"

  # add to external variables
  # external_variables "int foo, bar"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are generated automatically with rake make:upload
  
  
  # one line servo control 
  #
  # move_servo my_servo, amount
  #
  # example:
  # 
  #   class MoveServo < ArduinoSketch
  #
  #     external_vars :sensor_position => "int, 0", :servo_amount => "int, 0"
  #
  #     output_pin 4, :as => :my_servo, :min => 700, :max => 2200
  #     input_pin 1, :as => :sensor
  #     def loop
  #       sensor_position = analogRead(sensor)
  #       servo_amount = (sensor_position*2 + 500)
  #       move_servo my_servo, servo_amount
  #     end
  #   end
  #
  #
  #  supports multiple servos by storing variables in the serv struc array that is constructed when
  #  the :min and :max options are added to the output_pin method
  

add_servo_struct

void move_servo(int servo_num, int pulse_width)
{
  struct servo servo_name = serv[servo_num];

  int pw = pulse_width;
  /* apply the servo limits */
  if (pw > servo_name.max)
    pw = servo_name.max;
  if (pw < servo_name.min)
    pw = servo_name.min;

  if (millis() - servo_name.lastPulse >= servo_name.refreshTime)
    {
      pulse_servo(servo_name.pin, pw);
      servo_name.lastPulse = millis();
      // if (find_total_loop_time() < 10)
      // for debug:
      // digitalWrite( 5, HIGH );
      // 18 seems optimal, but we should let the users adjust with a servo option
      delay(18);
    }

}

void pulse_servo(int pin, int us) {
  digitalWrite( pin, HIGH );
  // pulseWidth
  delayMicroseconds( us );
  digitalWrite( pin, LOW );
  serv[pin].pulseWidth = us;
}






    

end

================================================
FILE: lib/plugins/smoother.rb
================================================
class Smoother < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)

  # add to directives
  plugin_directives "#define ARY_SIZE 10"

  # add to external variables
  external_variables "int *cur, *scan, *start, *end;", "int sm_ary[ARY_SIZE];", "int last_reading = 0;"

  # add the following to the setup method
  add_to_setup "scan = &sm_ary[0];", "cur = &sm_ary[0];", "start = &sm_ary[0];", "end = &sm_ary[ARY_SIZE-1];"

  # add an element to the array and return the average

int add_hysteresis(int reading, int hysteresis)
{
  if ( ((reading - last_reading) > hysteresis) || ((last_reading - reading) > hysteresis)) {

          last_reading = reading;
          return reading;
       }
     else
       return last_reading;
}

int smooth_average(int reading)
{
  int sum, cnt;
  cnt = 0;
  sum = 0;
  *cur = reading;
  cur++;
  for (scan = &sm_ary[0]; scan < &sm_ary[ARY_SIZE-1]; cnt++, scan++)
    sum += *scan;
  ptr_reset();
  return sum/cnt;
}

void ptr_reset(void)
{
  if (cur == end)
  {
    cur = &sm_ary[0];
  }
}



end

================================================
FILE: lib/plugins/spark_fun_serial_lcd.rb
================================================
class SparkFunSerialLcd < ArduinoPlugin
  
  # RAD plugins are c methods, directives, external variables and assignments and calls 
  # that may be added to the main setup method
  # function prototypes not needed since we generate them automatically
  
  # directives, external variables and setup assignments and calls can be added rails style (not c style)
  # hack from http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1209050315

  plugin_directives "#undef int", "#include <stdio.h>", "char _str[32];", "#define writeln(...) sprintf(_str, __VA_ARGS__); Serial.println(_str)"
  # add to directives
  #plugin_directives "#define EXAMPLE 10"

  # add to external variables
  external_variables "char status_message[40] = \"very cool\"", "char* msg[40]"

  # add the following to the setup method
  # add_to_setup "foo = 1";, "bar = 1;" "sub_setup();"
  
  # one or more methods may be added and prototypes are generated automatically with rake make:upload
  
# methods for sparkfun serial lcd SerLCD v2.5

void print_sensor_position_plus(int reading){


/*  writeln("sensor: %d ", reading); */
  Serial.print("sensor: ");
  Serial.print(reading);

  
}

void print_sensor_position(long pos){
  Serial.print(pos);
}

void lcd_first_line(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}

void lcd_second_line(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(192, BYTE);    //position
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(192, BYTE);    //position
}
void clearLCD(){
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(157, BYTE);    //light level.
}

void set_backlight_level(int level){  //turns on the backlight
  if (level > 29)
    level = 29;
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(157 + level, BYTE);    //light level.
}

void toggle_backlight(){  //turns off the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print("|");     //light level for off.
    Serial.print(1);
}

void set_splash(){
  selectLineOne();
  Serial.print(" Ruby + Auduino");
  selectLineTwo();
  Serial.print(" RAD 0.2.4+     ");
  Serial.print(0x7C, BYTE);   // decimal 124, command flag for backlight stuff
  Serial.print(10, BYTE);
}

void backlightOff(){  //turns off the backlight
    Serial.print(0x7C, BYTE);   // decimal 124, command flag for backlight stuff
    Serial.print(128, BYTE);     //light level for off.
}
void serCommand(){   // decimal 254, a general function to call the command flag for issuing all other commands   
  Serial.print(0xFE, BYTE);
}




    

end

================================================
FILE: lib/plugins/spectra_symbol.rb
================================================
class SpectraSymbol < ArduinoPlugin
  
# jdbarnhart
# 20080729
#
# crazy experiment in progress
# purpose
#
# retain last reading after finger is removed from spectrasymbol
# soft pot
#
# use
# two steps
#
#  one
#    declare :device => :sensor 
#    example:
#      input_pin 1, :as => :sensor_one, :device => :spectra
#
#  two
#    instead of:
#      my_lcd.print analogRead sensor_two
#      use soft_lock
#      my_lcd.print sensor_one.spectra_lock
#      
#
# notes:
# experimental settings for 100mm spectrasymbol
# 
# hysteresis is set at 5 
# amount of sensor drop is set to 3
# delay time (dtime) is 4
# cutoff set to 10
#
int soft_lock(int pin)

{
  int hyst = 5;
  int drop = 3;
  int dtime = 4;
  int cutoff = 10;
  int read;
  int r1;
  int r2;
  int r3;
  unsigned int i;
  read = analogRead(pin)/4;
  delay(dtime);
  r1 = analogRead(pin)/4;
  delay(dtime);
  r2 = analogRead(pin)/4;
  delay(dtime);
  r3 = analogRead(pin)/4;
  delay(dtime);
  for (i = 0; i < (int) (sizeof(spec) / sizeof(spec[0])); i++) {   
    if (pin == spec[i].pin) {
      if (((r3 - r2) > drop) && ((r2 - r1) > drop) && ((r1 - read) > drop)) 
        return spec[i].state - 10;
      else
      {
      if (read < cutoff) 
        return spec[i].state - 10;
      else
      {
          if (((read - spec[i].state) > hyst ) || ((spec[i].state - read) > hyst )) {
            spec[i].state = read;
            return spec[i].state - 10;
          } 
          else
            return spec[i].state - 10;   
        } 
      }   
    } 
  } 
}



end

================================================
FILE: lib/plugins/twitter_connect.rb
================================================
class TwitterConnect < ArduinoPlugin




void get_tweet() {
  // hack to pull 
}

uint32_t parsenumber(char *str) {
  uint32_t num = 0;
  char c;
  
  // grabs a number out of a string
  while (c = str[0]) {
   if ((c < '0') || (c > '9'))
     return num;
   num *= 10;
   num += c - '0';
   str++;
 }
 return num;
}


char * fetchtweet(void) {
  Serial.print("... fetching tweets....");
  uint8_t ret;
  char *found=0, *start=0, *end=0;
  
  tweet[0] = 0;  // reset the tweet
  ret = xport.reset();
  //Serial.print("Ret: "); Serial.print(ret, HEX);
  switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on reset!"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Bad response on reset!");
      return 0;
   }
   case ERROR_NONE: { 
    Serial.println("Reset OK!");
    break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // time to connect...
 
  ret = xport.connect(IPADDR, PORT);
    switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on connect"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Failed to connect");
      return 0;
   }
   case ERROR_NONE: { 
     Serial.println("Connected..."); break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // send the HTTP command, ie "GET /username/"
  
    xport.print("GET "); xport.println(HTTPPATH);
// the following works with instiki, but not on twitter...
//  xport.print("GET "); 
//  xport.print(HTTPPATH);
//  xport.println(" HTTP/1.1");
//  xport.print("Host: "); xport.println(HOSTNAME);
//  xport.println("");
    
  

  while (1) {
    // read one line from the xport at a time
    ret = xport.readline_timeout(linebuffer, 255, 4000); // 3s timeout
    // if we're using flow control, we can actually dump the line at the same time!
    // Serial.print(linebuffer);
    
    // look for an entry (the first one)
    found = strstr(linebuffer, "entry-title entry-content");
    if (((int)found) != 0) {
      start = strstr(found, ">") + 1;
      end = strstr(found, "</p>");
      if ((start != 0) && (end != 0)) {
        Serial.println("\n******Found first entry!*******");
        end[0] = 0;
        Serial.print(start);
        // save the tweet so we can display it later
        strncpy(tweet, start, TWEETLEN);
        tweet[TWEETLEN-1] = 0;
      }
    }
    
    // next we look for a status ID (which should correspond to the previous tweet)e
    // Serial.print(".");
    // Serial.print(linebuffer);
    found = strstr(linebuffer, "<div id=\"status_actions_");  
    if (((int)found) != 0) {
      start =  found + 25; // strlen("<span id=\"status_actions_")
      end = strstr(found, "\">");
      if ((start != 0) && (end != 0)) {
        Serial.println("\n******Found status ID!*******");
        end[0] = 0;
        Serial.println(start);
        // turn the string into a number
        __currstatus = parsenumber(start);
        Serial.println(__currstatus, DEC);
        
        // check if this is a nu tweet
        if (__currstatus > __laststatus) {
           __laststatus = __currstatus;
           Serial.println("New message");
           Serial.print(tweet);
        } else {
          tweet[0] = 0;
        }
       // flush the conn
       xport.flush(5000); // 5 second timeout
 
       if (tweet[0] == 0) { return 0; }
       else {return tweet; }
      }
    }
    
    if (((__errno == ERROR_TIMEDOUT) && xport.disconnected()) ||
        ((XPORT_DTRPIN == 0) &&
         (linebuffer[0] == 'D') && (linebuffer[1] == 0)))  {
       Serial.println("\nDisconnected...");
       return 0;
    }
  }
}

end


================================================
FILE: lib/rad/README.rdoc
================================================
=Welcome to RAD (Ruby Arduino Development) Quick Start Documentation

ArduinoSketch is the main access point for working with RAD. Sub-classes of ArduinoSketch have access to a wide array of convenient class methods (documented below) for doing the most common kinds of setup needed when programming the Arduino such as configuring input and output pins and establishing serial connections. Here is the canonical 'hello world' example of blinking a single LED in RAD:

test... to be continued if it works..

================================================
FILE: lib/rad/antiquated_todo.txt
================================================
-framework for translation to C (wrapper for RubyToAnsiC)
-framework for translation testing (want to test that each Rad method translates to the expected C)

-have to replace symbol & str definitions with "char name[]" ?

-maybe can't build rad.c dynamically? can use as helpers in writing it statically rad.rb and RubyToAnsiC as helpers in writing it. . .
-maybe there's a way to give RubyToC prototypes for the arduino library methods (or maybe include them directly) so that it will be able to figure out the signatures for my methods (otherwise it breaks because, for example, it can't figure out what read returns).
-speaking of which: all rad methods need to have a statically typed return value or else they won't be translatable to C. For example, as it stands #read may return a bool (if it calls digitalRead) or an int (if it calls analogRead). This may force me to take away much of the syntactic sugar

-how to handle setting up named pins:

declare the name with an underscore:
  int _led = 1;
and define an accessor for it:
  int led(){
    _led;
  }
Then, calling the method will get you the int.

-drop read and write custom methods (at least for now)? save time, save a whole step. Make it trivial to implement the whole library. . .

======================================================================================================
-the Arduino DSL is pretty good. Don't try to reinvent it for the board's api, add value on top of it!
======================================================================================================

-add constants HIGH, LOW, etc.

-design directory structure
-->where do we put the sketch files
-->where do the .c files get compiled to?

-design rad lib directory structure
/sketch
  my_sketch.rb
/build
  my_sketch.c
  rad.c
/rad
  /lib
  /specs
  Rakefile


-helper methods like blink

-proof of concept of build process



================================================
FILE: lib/rad/arduino_plugin.rb
================================================
## RAD plugins -- the start

## June 25, 2008
## jd@jdbarnhart.com
## 


# Disclaimer: This is only a first run at the notion of plugins and started off as just a way to keep from adding everything to ArduinoSketch.  
# ArduinoPlugin is the RAD class for adding "plugins" which add functionality such as servo control, special lcd screen methods, debounce methods, etc.. Sub-classes of ArduinoPlugin (the plugins) add  class methods for doing thing beyond the most common kinds of setup needed when programming the Arduino.  Here is an example of controlling a servo:
#
#   class MoveServo < ArduinoSketch
#
#     external_vars :sensor_position => "int, 0", :servo_amount => "int, 0"
#
#     output_pin 4, :as => :my_servo, :min => 700, :max => 2200
#     input_pin 1, :as => :sensor
#     def loop
#       sensor_position = analogRead(sensor)
#       servo_amount = (sensor_position*2 + 500)
#       move_servo my_servo, servo_amount
#     end
#   end
#
# 
# Here's one for latching an led

#   output_pin 5, :as => :red_led
#   input_pin 8, :as => :red_button, :latch => :off, # optional adjustment to amount of time for debounce (default 200) :adjust => 250
#                                                    # latch sets the led as on or off initially and sets up a array of structs to keep timing and state
#
#     def loop
#       debounce_toggle(red_button, red_led)
#     end
#   end
#
# Since this is a first pass, there is work to do here, such as 
#   checking if plugin methods are needed and only loading those that are, 
#   more compreshensive plugin organization (more railsish with tests, etc)
#   a scheme to encourage plugin authors and provide an easy way to avoid method and variable namespace collisions
#   a scheme to flag when a prerequisite plugin is required
# on with the show:



class ArduinoPlugin
  
def initialize #:nodoc:
  
  $plugin_directives = $plugin_directives || []
  $plugin_external_variables = $plugin_external_variables || []
  # moved to check_for_plugin_use $plugin_structs = $plugin_structs || {}
  $plugin_signatures = $plugin_signatures || []
  $plugin_methods = $plugin_methods || []
 # $plugin_methods_hash = $plugin_methods_hash || {}  ### new
 # $plugins_to_load = $plugins_to_load || []  ### new
  $add_to_setup = $add_to_setup || []
  $load_libraries = $load_libraries || []


end
  
# c declarations are automatic
# you won't need them in the plugins
# so, the first thing we can do is gather all the plugin methods, and scan the 
# sketch available plugins...
# if the sketch has them, we include the plugins in the build...
# otherwise not..

  def include_wire
    $load_libraries << "Wire" unless $load_libraries.include?("Wire")
  end


  def add_to_setup(*args)
    if args
       args.each do |arg|
         $add_to_setup << arg
       end
     end
  end


  def plugin_directives(*args)
    if args
       args.each do |arg|
         $plugin_directives << arg
       end
     end
  end


  def external_variables(*args)
    if args
       args.each do |arg|
         puts self.class
         puts "\tadding plugin external variables: #{arg}"
         # colons aptional
         colon  = arg[arg.length - 1, 1] == ";"  ? '' : ';' 
         $plugin_external_variables << "#{arg}#{colon}"
       end
     end
  end
  
  def add_blink_m_struct
    $plugin_structs[:blink_m] = <<-STR
    typedef struct _blinkm_script_line {
        uint8_t dur;
        uint8_t cmd[4];    // cmd,arg1,arg2,arg3
    } blinkm_script_line;
    STR
  end
  
  def self.add_blink_m_struct
    $plugin_structs[:blink_m] = <<-STR
    typedef struct _blinkm_script_line {
        uint8_t dur;
        uint8_t cmd[4];    // cmd,arg1,arg2,arg3
    } blinkm_script_line;
    STR
  end
  
  def add_debounce_struct
    $plugin_structs[:debounce] = <<-STR
    struct debounce {
      int state;
      int read;
      int prev;
      unsigned long time;
      unsigned long adjust;
    };
    STR
  end
  
  
  def add_servo_struct 
    $plugin_structs[:servo] = <<-STR
    struct servo {
      int pin;
      long unsigned pulseWidth;
      long unsigned lastPulse;
      long unsigned startPulse;
      long unsigned refreshTime;
      int min;
      int max;
    };
    STR
  end
  
  def self.add_debounce_struct
    $plugin_structs[:debounce] = <<-STR
    struct debounce {
      int state;
      int read;
      int prev;
      unsigned long time;
      unsigned long adjust;
    };
    STR
  end
  
  
  def self.add_servo_struct
    $plugin_structs[:servo] = <<-STR
    struct servo {
      int pin;
      long unsigned pulseWidth;
      long unsigned lastPulse;
      long unsigned startPulse;
      long unsigned refreshTime;
      int min;
      int max;
    };
    STR
  end
  
  def self.add_sensor_struct
    $plugin_structs[:sensor] = <<-STR
    struct hysteresis {
      int pin;
      int state;
    };
    STR
  end
  
  def self.add_spectra_struct
    $plugin_structs[:spectra] = <<-STR
    struct spectra {
      int pin;
      int state;
      int r1;
      int r2;
      int r3;
    };
    STR
  end
  

  def self.check_for_plugin_use(sketch_string, plugin_string, file_name) # rename klass to filename
    $plugin_structs = $plugin_structs || {}
    $plugin_methods_hash = $plugin_methods_hash || {}  
    $plugins_to_load = $plugins_to_load || []  
    plugin_signatures = []
    plugin_methods = []
    ## need a test for this
    ## fails on string interpolation, but since ruby_to_c also currently fails ...
    sketch_string = sketch_string.gsub(/#(?!\{.*\}).*/, "")
    plugin_signatures << plugin_string.scan(/^\s*(((#{PLUGIN_C_VAR_TYPES})\s*)+\w*\(.*\))/)
    # gather just the method name and then add to #plugin_methods_hash
    plugin_signatures[0].map {|sig| "#{sig[0]}"}.each {|m| plugin_methods << m.gsub!(/^.*\s(\w*)\(.*\)/, '\1')}
    # we don't know the methods yet, so... 
    $plugin_methods_hash[file_name] = plugin_methods
    $plugin_methods_hash.each do |k,meths|
      meths.each do |meth|
        if sketch_string.include?(meth)
           # load this plugin... 
           $plugins_to_load << k unless $plugins_to_load.include?(k)
         end
      end
    end

  end


  def self.process(plugin_string)
    plugin_signatures = []
    first_process = plugin_string 
    # todo: need to add plugin names to the methods, so we can add them as comments in the c code
    # gather the c methods
    $plugin_methods << first_process.scan(/^\s*(((#{PLUGIN_C_VAR_TYPES}).*\)).*(\n.*)*^\s*\})/)
    plugin_signatures << first_process.scan(/^\s((#{PLUGIN_C_VAR_TYPES}).*\(.*\))/)
    $plugin_signatures << plugin_signatures[0].map {|sig| "#{sig[0]};"}
    ## strip out the methods and pass it back 
    result = plugin_string
    # strip out the c methods so we have only ruby before eval
    result.gsub(/^\s*(#{PLUGIN_C_VAR_TYPES}).*(\n.*)*^\s*\}/, ""  )
    
  end
  
  private
  
  def add_struct(struct)
    
    
  end
    
end

================================================
FILE: lib/rad/arduino_sketch.rb
================================================
# ArduinoSketch is the main access point for working with RAD. Sub-classes of ArduinoSketch have access to a wide array of convenient class methods (documented below) for doing the most common kinds of setup needed when programming the Arduino such as configuring input and output pins and establishing serial connections. Here is the canonical 'hello world' example of blinking a single LED in RAD:
#
#   class HelloWorld < ArduinoSketch
#     output_pin 13, :as => :led
#     
#     def loop
#       blink 13, 500
#     end
#   end
#
# As you can see from this example, your ArduinoSketch sub-class can be dividied into two-parts: class methods for doing configuration and a loop method which will be run repeatedly at the Arduino's clock rate. Documentation for the various available class methods is below. The ArduinoSketch base class is designed to work with a series of rake tasks to automatically translate your loop method into C++ for compilation by the Arduino toolchain (see link://files/lib/rad/tasks/build_and_make_rake.html for details). See http://rad.rubyforge.org/examples for lots more examples of usage.
#
# ==Arduino built-in methods
# Thanks to this translation process you can take advantage of the complete Arduino software API (full docs here: http://www.arduino.cc/en/Reference/HomePage). What follows is the core of a RAD-Arduino dictionary for translating between RAD methods and the Arduino functionality they invoke, N.B. many Arduino methods have been left out (including the libraries for Time, Math, and Random Numbers, as the translation between them and their RAD counterparts should be relatively straightforward after perusing the examples here). For further details on each method, visit their Arduino documenation.
#
# <b>Digital I/O</b>
#
# digital_write(pin, value)
#
#   Arduino method: digitalWrite(pin, value) 
#
#   Description: "Ouputs either HIGH or LOW at a specified pin."
#   
#   Documentation: http://www.arduino.cc/en/Reference/DigitalWrite
#   
# digital_read(pin)
#
#   Arduino method: digitalRead(pin) 
#
#   Description: "Reads the value from a specified pin, it will be either HIGH or LOW."
#
#   Documentation: http://www.arduino.cc/en/Reference/DigitalRead
# 
# <b>Analog I/O</b>
#
# analog_read(pin) 
#
#   Arduino method: analogRead(pin)
#
#   Description: "Reads the value from the specified analog pin. The Arduino board contains a 6 channel 
#     (8 channels on the Mini), 10-bit analog to digital converter. This means that it will map input 
#     voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution
#     between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. It takes about 100
#     us (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second."
#
#   Documentation: http://www.arduino.cc/en/Reference/AnalogRead
#
# analog_write(pin, value)
#
#   Arduino method: analogWrite(pin, value)
#
#   Description: "Writes an analog value (PWM wave) to a pin. On newer Arduino boards (including the Mini
#     and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and 
#     serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11. Can be used 
#     to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite,
#     the pin will generate a steady wave until the next call to analogWrite (or a call to digitalRead or 
#     digitalWrite on the same pin)."
#
#   Documentation: http://www.arduino.cc/en/Reference/AnalogWrite
#
# <b>Serial Communication</b>
#
# serial_available()
#
#   Arduino method: Serial.available()
#   
#   Description: "Get the number of bytes (characters) available for reading over the serial port. 
#     Returns the number of bytes available to read in the serial buffer, or 0 if none are 
#     available. If any data has come in, Serial.available() will be greater than 0. The serial buffer
#     can hold up to 128 bytes."
#
#   Documentation: http://www.arduino.cc/en/Serial/Available
#
# serial_read()
#
#   Arduino method: Serial.read()
#
#   Description: "Reads incoming serial data and returns the first byte of incoming serial data 
#     available (or -1 if no data is available)"
#
#   Documentation: http://www.arduino.cc/en/Serial/Read
#
# serial_print(data)
#
#   Arduino method: Serial.print(data)
#
#   Description: "Prints data to the serial port."
#
#   Documentation: http://www.arduino.cc/en/Serial/Print
#
# serial_println(data)
#
#   Arduino method: Serial.println(data)
#
#   Description: "Prints a data to the serial port, followed by a carriage return character 
#     (ASCII 13, or '\r') and a newline character (ASCII 10, or '\n'). This command takes the 
#     same forms as Serial.print():"
#
#   Documentation: http://www.arduino.cc/en/Serial/Println
#
# serial_flush()
#
#   Arduino method: Serial.flush()
#
#   Description: "Flushes the buffer of incoming serial data. That is, any call to Serial.read() 
#     or Serial.available() will return only data received after the most recent call 
#     to Serial.flush()."
#
#   Documentation: http://www.arduino.cc/en/Serial/Flush
#
#   June 25, 2008
#   Added a new external variable method which keeps track 
#   external_vars :sensor_position => "int, 0", :feedback => "int", :pulseTime => "unsigned long, 0"
# 
#   added ability to write additional methods besides loop in the sketch 
#   since there is quite a bit of work to do with the c translation, it is easy to write a method that
#   won't compile or even translate into c, but for basics, it works.  
#   Note: stay basic and mindful that c is picky about variables and must make a decision
#   which will not always be what you want
#   also: for now, don't leave empty methods (something like foo = 1 cures this)
# 
#   Example:
#
#   class HelloMethods < ArduinoSketch
#     output_pin 13, :as => :led
#     
#     def loop
#       blink_it
#     end

#     def blink_it
#       blink 13, 500
#     end
#
#   end
#
#   
#   added pin methods for servos and latching which generate an array of structs to contain setup and status
#   input_pin 12, :as => :back_off_button, :latch => :off
#   input_pin 8, :as => :red_button, :latch => :off # adjust is optional with default set to 200
#
#   added add_to_setup method that takes a string of c code and adds it to setup
#   colons are options and will be added if not present  
#   no translation from ruby for now
#
#   example:
#   
#   add_to_setup "call_my_new_method();", "call_another();"  
#
#   added some checking to c translation that (hopefully) makes it a bit more predictable
#   most notably, we keep track of all external variables and let the translator know they exist 
#   
#   

class ArduinoSketch
  
  include ExternalVariableProcessing
  
  # find another way to do this
  @@twowire_inc	  = FALSE
  @@hwserial_inc  = FALSE

  
  def initialize #:nodoc:
    @servo_settings = [] # need modular way to add this
    @debounce_settings = [] # need modular way to add this
    @hysteresis_settings = []
    @spectra_settings = []
    @servo_pins = [] 
    @debounce_pins = []
    @hysteresis_pins = []
    @spectra_pins = []
    $external_array_vars = [] 
    $external_vars =[]
    $external_var_identifiers = []
    $sketch_methods = []
    $load_libraries ||= []
    $defines  ||= []
    $define_types = {}
    $array_types = {}
    $array_index_helpers = ('a'..'zz').to_a

    @declarations = []
    @pin_modes = {:output => [], :input => []}
    @pullups = []
    @other_setup = [] # specifically, Serial.begin
    @assembler_declarations = []
    @accessors = []
    @signatures = ["int main();"]
 
    helper_methods = []
    @helper_methods = helper_methods.join( "\n" )

  end
  

  
  # array "char buffer[32]"
  # result: char buffer[32];
  # array "char buffer[32]"
  # result: char buffer[32];
  # todo 
  # need to feed array external array identifiers to rtc if they are in plugins or libraries, (not so sure about this will do more testing)
  def array(arg)
    if arg
        arg = arg.chomp.rstrip.lstrip
        arg.sub!("@","__")
        name = arg.scan(/\s*(\w*)\[\d*\]?/).first.first
        # help rad_processor do a better job with array types
        types = ["int", "long", "char*", "unsigned int", "unsigned long", "byte", "bool", "float" ]
        types.each_with_index do |type, i|
          @type = types[i] if /#{type}/ =~ arg
        end
        raise ArgumentError, "type not currently supported.. got: #{arg}.  Currently supporting #{types.join(", ")}" unless @type

        arg = "#{arg};" unless arg[-1,1] == ";"
        $array_types[name] = @type
        @type = nil
        $external_var_identifiers << name unless $external_var_identifiers.include?(name)
        # add array_name declaration
        $external_array_vars << arg unless $external_array_vars.include?(arg)
    end
  end
  
  # define "DS1307_SEC 0"
  # result: #define DS1307_SEC 0
  # note we send the constant identifiers and type to our rad_type_checker
  # however, it only knows about long, float, str....
  # so we don't send ints ...yet..
  # need more testing
  def define(arg)
    if arg
        arg = arg.chomp.rstrip.lstrip
        name = arg.split(" ").first
        value = arg.gsub!("#{name} ","")
        # negative
        if value =~ /^-(\d|x)*$/ 
           type = "long"
         # negative float
         elsif value =~ /^-(\d|\.|x)*$/ 
           type = "float" 
         elsif value =~ /[a-zA-Z]/
           type = "str"
           value = "\"#{value}\""
         elsif value !~ /(\.|x)/
           type = "long"
         elsif value =~ /(\d*\.\d*)/ # and no 
           type = "float"
         elsif value =~ /0x\d\d/
           type = "byte"
         else 
           raise ArgumentError, "opps, could not determine the define type, got #{value}"
         end
        $define_types[name] = type
        arg = "#define #{name} #{value}"
        $defines << arg
        dummy_for_testing = arg, type
    end
  end
  
  # Configure a single pin for output and setup a method to refer to that pin, i.e.:
  #
  #   output_pin 7, :as => :led
  #
  # would configure pin 7 as an output and let you refer to it from the then on by calling
  # the `led` method in your loop like so:
  # 
  #   def loop
  #     digital_write led, ON
  #   end
  #
  def output_pin(num, opts={})
    raise ArgumentError, "can only define pin from Fixnum, got #{num.class}" unless num.is_a?(Fixnum)
    @pin_modes[:output] << num
    if opts[:as]
      if opts[:device]
        case opts[:device]
        when :servo
          servo_setup(num, opts)
          return # don't use declarations, accessor, signatures below
        when :pa_lcd || :pa_LCD
          pa_lcd_setup(num, opts)
          return 
        when :sf_lcd || :sf_LCD
          sf_lcd_setup(num, opts)
          return         
        when :freq_out || :freq_gen || :frequency_generator
          frequency_timer(num, opts)
          return
        when :i2c
          two_wire(num, opts) unless @@twowire_inc
          return #
        when :i2c_eeprom
          two_wire(num, opts) unless @@twowire_inc
          i2c_eeprom(num, opts)
          return #
        when :i2c_ds1307
          two_wire(num, opts) unless @@twowire_inc
          ds1307(num, opts) 
          return #
        when :i2c_blinkm
          two_wire(num, opts) unless @@twowire_inc
          blinkm
          return #
        when :onewire
          one_wire(num, opts)
          return #
        when :ethernet
          ethernet(num, opts)
          return #
        else
          raise ArgumentError, "today's device choices are: :servo, :pa_lcd, :sf_lcd, :freq_out,:i2c, :i2c_eeprom, :i2c_ds1307, and :i2c_blinkm  got #{opts[:device]}"
        end
      end
      
  # add state variables for outputs with :state => :on or :off -- useful for toggling a light with output_toggle -- need to make this more modular
      if opts[:state] 
        # add debounce settings to dbce struct array
        ArduinoPlugin.add_debounce_struct
        @debounce_pins << num
        state = opts[:latch] == :on ? 1 : 0
        prev = opts[:latch] == :on ? 0 : 1
        adjust = opts[:adjust] ? opts[:adjust] : 200
        @debounce_settings <<  "dbce[#{num}].state = #{state}, dbce[#{num}].read = 0, dbce[#{num}].prev = #{prev}, dbce[#{num}].time = 0, dbce[#{num}].adjust = #{adjust}"
      end
      
      @declarations << "int _#{opts[ :as ]} = #{num};"
      
      accessor = []
      accessor << "int #{opts[ :as ]}() {"
      accessor << "\treturn _#{opts[ :as ]};"
      accessor << "}"
      @accessors << accessor.join( "\n" )
      
      @signatures << "int #{opts[ :as ]}();"
    end
  end
  
  
  # Configure a single pin for input and setup a method to refer to that pin, i.e.:
  #
  #   input_pin 3, :as => :button
  #
  # would configure pin 3 as an input and let you refer to it from the then on by calling
  # the `button` method in your loop like so:
  # 
  #   def loop
  #     digital_write led if digital_read button
  #   end
  #
  def input_pin(num, opts={})
    raise ArgumentError, "can only define pin from Fixnum, got #{num.class}" unless num.is_a?(Fixnum)
    @pin_modes[:input] << num
    if opts[:as]
      # transitioning to :device => :button syntax
      if opts[:latch] || opts[:device] == :button
        if opts[:device] == :button
          opts[:latch] ||= :off
        end
        # add debounce settings to dbce struct array
        ArduinoPlugin.add_debounce_struct
        @debounce_pins << num
        state = opts[:latch] == :on ? 1 : 0
        prev = opts[:latch] == :on ? 0 : 1
        adjust = opts[:adjust] ? opts[:adjust] : 200
        @debounce_settings <<  "dbce[#{num}].state = #{state}, dbce[#{num}].read = 0, dbce[#{num}].prev = #{prev}, dbce[#{num}].time = 0, dbce[#{num}].adjust = #{adjust}"
      end
      if opts[:device] == :sensor
        ArduinoPlugin.add_sensor_struct
        count = @hysteresis_pins.length
        @hysteresis_pins << num
        @hysteresis_settings << "hyst[#{count}].pin = #{num}, hyst[#{count}].state = 0"
      end
      if opts[:device] == :spectra
        ArduinoPlugin.add_spectra_struct
        count = @spectra_pins.length
        @spectra_pins << num
        @spectra_settings << "spec[#{count}].pin = #{num}, spec[#{count}].state = 10, spec[#{count}].r1 = 0, spec[#{count}].r2 = 0, spec[#{count}].r3 = 0"
      end
      @declarations << "int _#{opts[ :as ]} = #{num};"

      accessor = []
      accessor << "int #{opts[ :as ]}() {"
      accessor << "\treturn _#{opts[ :as ]};"
      accessor << "}"
      @accessors << accessor.join( "\n" )
      
      @signatures << "int #{opts[ :as ]}();"
    end
    @pullups << num if opts[:as]
  end
  
  # Like ArduinoSketch#input_pin but configure more than one input pin simultaneously. Takes an array of pin numbers. 
  def input_pins(nums)
    ar = Array(nums)
    ar.each {|n| input_pin(n)} 
  end
  
  def add(st) #:nodoc:
    @helper_methods << "\n#{st}\n"
  end
  
  # Configure Arduino for serial communication. Optionally, set the baud rate:
  #
  #   serial_begin :rate => 2400
  #
  # default is 9600. See http://www.arduino.cc/en/Serial/Begin for more details.
  # 
  def serial_begin(opts={})
    rate = opts[:rate] ? opts[:rate] : 9600
    @other_setup << "Serial.begin(#{rate});"
    @@hwserial_inc = TRUE
  end
  

  def formatted_print(opts={})

    buffer_size = opts[:buffer_size] ? opts[:buffer_size] : 64
    
    if opts[:as]
      @@sprintf_inc ||= FALSE
      if @@sprintf_inc == FALSE
        @@sprintf_inc = TRUE
        accessor = []
        accessor << "\n#undef int\n#include <stdio.h>"
        accessor << "#define write_line(...) sprintf(#{opts[:as]},__VA_ARGS__);"
        @accessors << accessor.join( "\n" )
        array("char #{opts[:as]}[#{buffer_size}]") 
      end
    end
  end

  


  def compose_setup #:nodoc: also composes headers and signatures

    declarations = []
    plugin_directives = []
    signatures = []
    external_vars = []
    setup = []
    additional_setup =[]
    helpers = []
    main = []
    result = []
    
    declarations << comment_box( "Auto-generated by RAD" )
    
    declarations << "#include <WProgram.h>\n"
    declarations << "#include <SoftwareSerial.h>\n"
    $load_libraries.each { |lib| declarations << "#include <#{lib}.h>" } unless $load_libraries.nil?
    $defines.each { |d| declarations << d }

    plugin_directives << comment_box( 'plugin directives' )
    $plugin_directives.each {|dir| plugin_directives << dir } unless $plugin_directives.nil? ||  $plugin_directives.empty?
    
    signatures << comment_box( 'method signatures' )
    signatures << "void loop();"
    signatures << "void setup();"
    signatures << "// sketch signatures"
    @signatures.each {|sig| signatures << sig}
    signatures << "// plugin signatures"
    $plugin_signatures.each {|sig| signatures << sig } unless $plugin_signatures.nil? || $plugin_signatures.empty?
    external_vars << "\n" + comment_box( "plugin external variables" )
    $plugin_external_variables.each { |meth| external_vars << meth } unless $plugin_external_variables.nil? || $plugin_external_variables.empty?
    
    signatures << "\n" + comment_box( "plugin structs" )
    $plugin_structs.each { |k,v| signatures << v } unless $plugin_structs.nil? || $plugin_structs.empty?

    external_vars << "\n" + comment_box( "sketch external variables" )
    
    $external_vars.each {|v| external_vars << v }
    external_vars << "" 
    external_vars << "// servo_settings array"

    array_size = @servo_settings.empty? ? 1 : @servo_pins.max + 1 # conserve space if no variables needed
    external_vars << "struct servo serv[#{array_size}] = { #{@servo_settings.join(", ")} };" if $plugin_structs[:servo]
    external_vars << "" 

    external_vars << "// debounce array"
    array_size = @debounce_settings.empty? ? 1 : @debounce_pins.max + 1 # conserve space if no variables needed
    external_vars << "struct debounce dbce[#{array_size}] = { #{@debounce_settings.join(", ")} };" if $plugin_structs[:debounce]
    external_vars << ""
    
    external_vars << "// hysteresis array"
    h_array_size = @hysteresis_settings.empty? ? 1 : @hysteresis_pins.length + 1 # conserve space if no variables needed
    external_vars << "struct hysteresis hyst[#{h_array_size}] = { #{@hysteresis_settings.join(", ")} };" if $plugin_structs[:sensor]
    external_vars << ""
    
    external_vars << "// spectrasymbol soft pot array"
    sp_array_size = @spectra_settings.empty? ? 1 : @spectra_pins.length + 1 # conserve space if no variables needed
    external_vars << "struct spectra spec[#{sp_array_size}] = { #{@spectra_settings.join(", ")} };" if $plugin_structs[:spectra]
    external_vars << ""
    
    $external_array_vars.each { |var| external_vars << var } if $external_array_vars

    external_vars << "\n" + comment_box( "variable and accessors" )
    @declarations.each {|dec| external_vars << dec}
    external_vars << ""     
    @accessors.each {|ac| external_vars << ac}

    # fix naming
    external_vars << "\n" + comment_box( "assembler declarations" )
    unless @assembler_declarations.empty?
      external_vars << <<-CODE
         extern "C" {
           #{@assembler_declarations.join("\n")}
         }
      CODE
    end

    external_vars << "\n" + comment_box( "setup" )
    setup << "void setup() {"
    setup << "\t// pin modes"
    
    @pin_modes.each do |k,v|
      v.each do |value| 
        setup << "\tpinMode(#{value}, #{k.to_s.upcase});"
      end
    end

    @pullups.each do |pin|
	    setup << "\tdigitalWrite( #{pin}, HIGH ); // enable pull-up resistor for input"
    end
    
    unless $add_to_setup.nil? || $add_to_setup.empty?
      setup << "\t// setup from plugins via add_to_setup method"
      $add_to_setup.each {|item| setup << "\t#{item}"}
    end
    
    unless @other_setup.empty?
      setup << "\t// other setup"
      setup << @other_setup.join( "\n" )
    end
    
    additional_setup << "}\n"
    
    helpers << comment_box( "helper methods" )
    helpers << "\n// RAD built-in helpers"
    helpers << @helper_methods.lstrip
    
    helpers << "\n" + comment_box( "plugin methods" )  
    # need to add plugin name to this... 
    $plugin_methods.each { |meth| helpers << "#{meth[0][0]}\n" } unless $plugin_methods.nil? || $plugin_methods.empty?
    
    if @@hwserial_inc == TRUE
      helpers << "\n// serial helpers"
      helpers << serial_boilerplate.lstrip
    end
    
    main << "\n" + comment_box( "main() function" )
    main << "int main() {"
    main << "\tinit();"
    main << "\tsetup();"
    main << "\tfor( ;; ) { loop(); }"
    main << "\treturn 0;"
    main << "}"

    main << "\n" + comment_box( "loop!  Autogenerated by RubyToC, sorry it's ugly." )

  return [declarations, plugin_directives, signatures, external_vars, setup, additional_setup, helpers, main]

  end
  
  
  # Write inline assembler code. 'Name' is a symbol representing the name of the function to be defined in the assembly code; 'signature' is the function signature for the function being defined; and 'code' is the assembly code itself (both of these last two arguments are strings). See an example here: http://rad.rubyforge.org/examples/assembler_test.html
  def assembler(name, signature, code)
    @assembler_declarations << signature
    assembler_code = <<-CODE
      .file "#{name}.S"
      .arch #{Makefile.hardware_params['mcu']}
      .global __do_copy_data
      .global __do_clear_bss
      .text
    .global #{name}
      .type #{name}, @function
    #{code}
    CODE
            
    File.open(File.expand_path("#{RAD_ROOT}") + "/#{PROJECT_DIR_NAME}/#{name}.S", "w"){|f| f << assembler_code}
  end
  
  def self.pre_process(sketch_string) #:nodoc:
    result = sketch_string 
    # add external vars to each method (needed for better translation, will be removed in make:upload)
    result.gsub!(/(^\s*def\s.\w*(\(.*\))?)/, '\1' + " \n #{$external_vars.join("  \n ")}"  )
    # gather method names
    sketch_methods = result.scan(/^\s*def\s.\w*/)
    sketch_methods.each {|m| $sketch_methods << m.gsub(/\s*def\s*/, "") }
    
    result.gsub!("HIGH", "1")
    result.gsub!("LOW", "0")
    result.gsub!("ON", "1")
    result.gsub!("OFF", "0")
    result
  end
  
  def self.add_to_setup(meth) 
    meth = meth.gsub("setup", "additional_setup")
    post_process_ruby_to_c_methods(meth)
  end
  
  def self.post_process_ruby_to_c_methods(e)      
    clean_c_methods = []
      # need to take a look at the \(unsigned in the line below not sure if we are really trying to catch something like that
      if e !~ /^\s*(#{C_VAR_TYPES})(\W{1,6}|\(unsigned\()(#{$external_var_identifiers.join("|")})/ || $external_var_identifiers.empty?
        # use the list of identifers the external_vars method of the sketch and remove the parens the ruby2c sometime adds to variables
        # keep an eye on the gsub!.. are we getting nil errors
        # and more recently, the \b
        e.gsub!(/\b((#{$external_var_identifiers.join("|")})\(\))/, '\2')  unless $external_var_identifiers.empty?
        clean_c_methods << e
      end
      return clean_c_methods.join( "\n" )
  end
  

  def comment_box( content ) #:nodoc:
    out = []
    out << "/" * 74
    out << "// " + content
    out << "/" * 74
    
    return out.join( "\n" )
  end  

  
end

================================================
FILE: lib/rad/darwin_installer.rb
================================================
class DarwinInstaller
  def self.install!
    puts "Downloading arduino-0012 for Mac from Arduino.cc"
    File.open("/Applications/arduino-0012.zip", "w") do |file|
      pbar = nil
      file << open("http://www.arduino.cc/files/arduino-0012-mac.zip",
      :content_length_proc => lambda {|t|
        if t && 0 < t
          pbar = ProgressBar.new(" Progress", t)
          pbar.file_transfer_mode
        end
      },
      :progress_proc => lambda {|s|
        pbar.set s if pbar
      }).read
      pbar.finish
    end
    puts "Unzipping..."
    `cd /Applications; unzip arduino-0012.zip`
    `rm /Applications/arduino-0012.zip`
    puts "installed Arduino here: /Applications/arduino-0012"
  end
end

================================================
FILE: lib/rad/generators/makefile/makefile.erb
================================================
# Arduino makefile
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment (or Java).
#
# The Arduino environment does preliminary processing on a sketch before
# compiling it.  If you're using this makefile instead, you'll need to do
# a few things differently:
#
#   - Give your program's file a .cpp extension (e.g. foo.cpp).
#
#   - Put this line at top of your code: #include <WProgram.h>
#
#   - Write prototypes for all your functions (or define them before you
#     call them).  A prototype declares the types of parameters a
#     function will take and what type of value it will return.  This
#     means that you can have a call to a function before the definition
#     of the function.  A function prototype looks like the first line of
#     the function, with a semi-colon at the end.  For example:
#     int digitalRead(int pin);
#
#   - Write a main() function for your program that returns an int, calls
#     init() and setup() once (in that order), and then calls loop()
#     repeatedly():
#
#	int main()
#	{
#		init();
#		setup();
#
#		for (;;)
#			loop();
#
#		return 0;
#	}
#
# Instructions for using the makefile:
#
#  1. Copy this file into the folder with your sketch.
#
#  2. Below, modify the line containing "TARGET" to refer to the name of
#     of your program's file without an extension (e.g. TARGET = foo).
#
#  3. Modify the line containg "ARDUINO" to point the directory that
#     contains the Arduino core (for normal Arduino installations, this
#     is the hardware/cores/arduino sub-directory).
#
#  4. Modify the line containing "PORT" to refer to the filename
#     representing the USB or serial connection to your Arduino board
#     (e.g. PORT = /dev/tty.USB0).  If the exact name of this file
#     changes, you can use * as a wildcard (e.g. PORT = /dev/tty.USB*).
#
#  5. At the command line, change to the directory containing your
#     program's file and the makefile.
#
#  6. Type "make" and press enter to compile/verify your program.
#
#  7. Type "make upload", reset your Arduino board, and press enter  to
#     upload your program to the Arduino board.
#
# $Id$

PORT = <%= params['serial_port'] %>
TARGET = <%= params['target'] %>
ARDUINO = <%= params['arduino_root'] %>/hardware/cores/arduino
SOFTWARE_SERIAL = <%= params['arduino_root'] %>/hardware/libraries/SoftwareSerial
LIBRARY_ROOT = <%= params['libraries_root'] %>
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c <%= params['twi_c'] %>
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(SOFTWARE_SERIAL)/SoftwareSerial.cpp $(ARDUINO)/Print.cpp<%= params['libraries'].collect{|l| " $(LIBRARY_ROOT)/#{ l }/#{l }.cpp"}.join('') %>
MCU = <%= params['mcu'] %>
<% if params['asm_files'] %>ASRC = <%= params['asm_files'].join(' ') %><% end %>
F_CPU = 16000000
FORMAT = ihex
UPLOAD_RATE = 19200
BIN_DIR = <%= params['arduino_root'] %>/hardware/tools/avr/bin

# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile

# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG = stabs

OPT = s

# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)

# Place -I options here
CINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %>
+CXXINCS = -I$(ARDUINO) -I$(SOFTWARE_SERIAL)<% params['libraries'].each do |l| %> -I$(LIBRARY_ROOT)/<%= l %><% end %>

# Compiler flag to set the C Standard level.
# c89   - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99   - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)

CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
LDFLAGS = -lm


# Programming support using avrdude. Settings and variables.
AVRDUDE_PROGRAMMER = stk500
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
AVRDUDE_FLAGS = -F -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
  -b $(UPLOAD_RATE) -C <%= params['arduino_root'] %>/hardware/tools/avr/etc/avrdude.conf

# Program settings
CC = $(BIN_DIR)/avr-gcc
CXX = $(BIN_DIR)/avr-g++
OBJCOPY = $(BIN_DIR)/avr-objcopy
OBJDUMP = $(BIN_DIR)/avr-objdump
AR  = $(BIN_DIR)/avr-ar
SIZE = $(BIN_DIR)/avr-size
NM = $(BIN_DIR)/avr-nm
AVRDUDE = $(BIN_DIR)/avrdude
REMOVE = rm -f
MV = mv -f

# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)

# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)


# Default target.
all: build

build: elf hex

elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss 
sym: $(TARGET).sym

# Program the device.  
upload: $(TARGET).hex
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)




# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000 


coff: $(TARGET).elf
	$(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof


extcoff: $(TARGET).elf
	$(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof


.SUFFIXES: .elf .hex .eep .lss .sym

.elf.hex:
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@

.elf.eep:
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@

# Create extended listing file from ELF output file.
.elf.lss:
	$(OBJDUMP) -h -S $< > $@

# Create a symbol table from ELF output file.
.elf.sym:
	$(NM) -n $< > $@


core.a: $(OBJ)
	@for i in $(OBJ); do echo $(AR) rcs core.a $$i; $(AR) rcs core.a $$i; done

# Link: create ELF output file from library.
$(TARGET).elf: core.a
	$(CC) $(ALL_CFLAGS) -o $@ $(TARGET).cpp -L. core.a $(LDFLAGS)

# Compile: create object files from C++ source files.
.cpp.o:
	$(CXX) -c $(ALL_CXXFLAGS) $< -o $@ 

# Compile: create object files from C source files.
.c.o:
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 


# Compile: create assembler files from C source files.
.c.s:
	$(CC) -S $(ALL_CFLAGS) $< -o $@


# Assemble: create object files from assembler source files.
.S.o:
	$(CC) -c $(ALL_ASFLAGS) $< -o $@



# Target: clean project.
clean:
	$(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
	$(TARGET).map $(TARGET).sym $(TARGET).lss core.a \
	$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)

depend:
	if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
	then \
		sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
			$(MAKEFILE).$$$$ && \
		$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
	fi
	echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
		>> $(MAKEFILE); \
	$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)

.PHONY:	all build elf hex eep lss sym program coff extcoff clean depend


================================================
FILE: lib/rad/generators/makefile/makefile.rb
================================================
require 'erb'
require 'yaml'

class Makefile
  class << self
    
    # build the sketch Makefile for the given template based on the values in its software and hardware config files
    def compose_for_sketch(build_dir)
      params = hardware_params.merge software_params
      params['target'] = build_dir.split("/").last
           
      params['libraries_root'] = "#{File.expand_path(RAD_ROOT)}/vendor/libraries"
      params['libraries'] = $load_libraries # load only libraries used 
      
      # needed along with ugly hack of including another copy of twi.h in wire, when using the Wire.h library
      params['twi_c'] = $load_libraries.include?("Wire") ? "#{params['arduino_root']}/hardware/libraries/Wire/utility/twi.c" : "" 
      
      params['asm_files'] = Dir.entries( File.expand_path(RAD_ROOT) + "/" + PROJECT_DIR_NAME ).select{|e| e =~ /\.S/}            
            
      e = ERB.new File.read("#{File.dirname(__FILE__)}/makefile.erb")
      
      File.open("#{build_dir}/Makefile", "w") do |f|
        f << e.result(binding)
      end
    end
        
    def hardware_params
      return @hardware_params if @hardware_params
      return @hardware_params = YAML.load_file( "#{RAD_ROOT}/config/hardware.yml")
    end
      
    def software_params
      return @software_params if @software_params
      return @software_params = YAML.load_file( "#{RAD_ROOT}/config/software.yml" )
    end
      
  end
end

================================================
FILE: lib/rad/hardware_library.rb
================================================
class HardwareLibrary < ArduinoSketch
  
  def initialize
    super
  end
  
  # Treat a pair of digital I/O pins as a serial line. See: http://www.arduino.cc/en/Tutorial/SoftwareSerial
  def software_serial(rx, tx, opts={})
    raise ArgumentError, "can only define rx from Fixnum, got #{rx.class}" unless rx.is_a?(Fixnum)
    raise ArgumentError, "can only define tx from Fixnum, got #{tx.class}" unless tx.is_a?(Fixnum)

    output_pin(tx)
    input_pin(rx)

    rate = opts[:rate] ? opts[:rate] : 9600
    if opts[:as]
      @declarations << "SoftwareSerial _#{opts[ :as ]} = SoftwareSerial(#{rx}, #{tx});"
      accessor = <<-STR
        SoftwareSerial& #{opts[ :as ]}() {
        return _#{opts[ :as ]};
        }
      STR
      @@swser_inc ||= FALSE
      if (@@swser_inc == FALSE) # on second instance this stuff can't be repeated
        @@swser_inc = TRUE
        accessor += <<-STR
        int read(SoftwareSerial& s) {
          return s.read();
        }
        void println( SoftwareSerial& s, char* str ) {
          return s.println( str );
        }
        void print( SoftwareSerial& s, char* str ) {
          return s.print( str );
        }
        void println( SoftwareSerial& s, int i ) {
          return s.println( i );
        }
        void print( SoftwareSerial& s, int i ) {
          return s.print( i );
        }
        STR
      end
      @accessors << accessor

      @signatures << "SoftwareSerial& #{opts[ :as ]}();"

      @other_setup << "\t_#{opts[ :as ]}.begin(#{rate});"
    end
  end 	
  
  # use the pa lcd library
  def pa_lcd_setup(num, opts)
    if opts[:geometry]
      raise ArgumentError, "can only define pin from Fixnum, got #{opts[:geometry]}" unless opts[:geometry].is_a?(Fixnum)
      raise ArgumentError, "pa_lcd geometry must be 216, 220, 224, 240, 416, 420, got #{opts[:geometry]}" unless opts[:geometry].to_s =~ /(216|220|224|240|416|420)/
    end
    # move to plugin and load plugin
    # what's the default?
     opts[:rate] ||= 9600
    rate = opts[:rate] ? opts[:rate] : 9600
    swser_LCDpa(num, opts)
  end

  def swser_LCDpa(tx, opts={})
    raise ArgumentError, "can only define tx from Fixnum, got #{tx.class}" unless tx.is_a?(Fixnum)

    rate = opts[:rate] ? opts[:rate] : 9600
    geometry = opts[:geometry] ? opts[:geometry] : 0
    if opts[:as] 
      @declarations << "SWSerLCDpa _#{opts[ :as ]} = SWSerLCDpa(#{tx}, #{geometry});"
      $load_libraries << "SWSerLCDpa"
      accessor = <<-STR
        SWSerLCDpa& #{opts[ :as ]}() {
          return _#{opts[ :as ]};
        }
      STR
      @@slcdpa_inc ||= FALSE
      if (@@slcdpa_inc == FALSE)	# on second instance this stuff can't be repeated - BBR
        @@slcdpa_inc = TRUE
        # ------------------- print generics -------------------------------
        accessor += <<-STR			  
        void print( SWSerLCDpa& s, uint8_t b ) {
          return s.print( b );
        }
        void print( SWSerLCDpa& s, const char *str ) {
          return s.print( str );
        }
        void print( SWSerLCDpa& s, char c ) {
          return s.print( c );
        }
        void print( SWSerLCDpa& s, int i ) {
          return s.print( i );
        }
        void print( SWSerLCDpa& s, unsigned int i ) {
          return s.print( i );
        }
        void print( SWSerLCDpa& s, long i ) {
          return s.print( i );
        }
        void print( SWSerLCDpa& s, unsigned long i ) {
          return s.print( i );
        }
        void print( SWSerLCDpa& s, long i, int b ) {
          return s.print( i, b );
        }
        STR
        # ------------------ PA-LCD specific functions ---------------------------------
        accessor += <<-STR
        void clearscr(SWSerLCDpa& s) {
          return s.clearscr();
        }
        void clearscr(SWSerLCDpa& s, const char *str) {
          return s.clearscr(str);
        }
        void clearscr(SWSerLCDpa& s, int n) {
          return s.clearscr(n);
        }
        void clearscr(SWSerLCDpa& s, long n, int b) {
          return s.clearscr(n, b);
        }
        void clearline(SWSerLCDpa& s, int line) {
          return s.clearline( line );
        }
        void clearline(SWSerLCDpa& s, int line, const char *str) {
          return s.clearline( line, str );
        }
        void clearline(SWSerLCDpa& s, int line, int n) {
          return s.clearline( line, n );
        }
        void clearline(SWSerLCDpa& s, int line, long n,  int b) {
          return s.clearline( line, n, b );
        }
        void home( SWSerLCDpa& s) {
          return s.home();
        }
        void home( SWSerLCDpa& s, const char *str) {
          return s.home( str );
        }
        voi
Download .txt
gitextract_7rauuwcn/

├── .gitignore
├── History.txt
├── License.txt
├── Manifest.txt
├── README.markdown
├── Rakefile
├── bin/
│   └── rad
├── lib/
│   ├── examples/
│   │   ├── add_hysteresis.rb
│   │   ├── basic_blink.rb
│   │   ├── blink_m_address_assignment.rb
│   │   ├── blink_m_hello.rb
│   │   ├── blink_m_multi.rb
│   │   ├── blink_with_serial.rb
│   │   ├── configure_pa_lcd_boot.rb
│   │   ├── debounce_methods.rb
│   │   ├── external_variable_fu.rb
│   │   ├── external_variables.rb
│   │   ├── first_sound.rb
│   │   ├── frequency_generator.rb
│   │   ├── hello_array.rb
│   │   ├── hello_array2.rb
│   │   ├── hello_array_eeprom.rb
│   │   ├── hello_clock.rb
│   │   ├── hello_eeprom.rb
│   │   ├── hello_eeprom_lcdpa.rb
│   │   ├── hello_format_print.rb
│   │   ├── hello_lcd_charset.rb
│   │   ├── hello_pa_lcd.rb
│   │   ├── hello_servos.rb
│   │   ├── hello_spectra_sound.rb
│   │   ├── hello_world.rb
│   │   ├── hello_xbee.rb
│   │   ├── hysteresis_duel.rb
│   │   ├── i2c_with_clock_chip.rb
│   │   ├── midi_beat_box.rb
│   │   ├── midi_scales.rb
│   │   ├── motor_knob.rb
│   │   ├── servo_buttons.rb
│   │   ├── servo_calibrate_continuous.rb
│   │   ├── servo_throttle.rb
│   │   ├── software_serial.rb
│   │   ├── sparkfun_lcd.rb
│   │   ├── spectra_soft_pot.rb
│   │   ├── times_method.rb
│   │   ├── toggle.rb
│   │   ├── twitter.rb
│   │   └── two_wire.rb
│   ├── libraries/
│   │   └── Wire/
│   │       └── utility/
│   │           ├── twi.c
│   │           └── twi.h
│   ├── plugins/
│   │   ├── bitwise_ops.rb
│   │   ├── blink.rb
│   │   ├── blink_m.rb
│   │   ├── debounce.rb
│   │   ├── debug_output_to_lcd.rb
│   │   ├── hysteresis.rb
│   │   ├── input_output_state.rb
│   │   ├── lcd_padding.rb
│   │   ├── mem_test.rb
│   │   ├── midi.rb
│   │   ├── parallax_ping.rb
│   │   ├── servo_pulse.rb
│   │   ├── servo_setup.rb
│   │   ├── smoother.rb
│   │   ├── spark_fun_serial_lcd.rb
│   │   ├── spectra_symbol.rb
│   │   └── twitter_connect.rb
│   ├── rad/
│   │   ├── README.rdoc
│   │   ├── antiquated_todo.txt
│   │   ├── arduino_plugin.rb
│   │   ├── arduino_sketch.rb
│   │   ├── darwin_installer.rb
│   │   ├── generators/
│   │   │   └── makefile/
│   │   │       ├── makefile.erb
│   │   │       └── makefile.rb
│   │   ├── hardware_library.rb
│   │   ├── init.rb
│   │   ├── linux_installer.rb
│   │   ├── progressbar.rb
│   │   ├── rad_processor.rb
│   │   ├── rad_rewriter.rb
│   │   ├── rad_type_checker.rb
│   │   ├── sim/
│   │   │   └── arduino_sketch.rb
│   │   ├── sketch_compiler.rb
│   │   ├── tasks/
│   │   │   ├── build_and_make.rake
│   │   │   └── rad.rb
│   │   ├── todo.txt
│   │   ├── variable_processing.rb
│   │   └── version.rb
│   └── rad.rb
├── rad.gemspec
├── scripts/
│   └── txt2html
├── setup.rb
├── spec/
│   ├── examples/
│   │   ├── hello_world.rb
│   │   └── serial_motor.rb
│   ├── models/
│   │   ├── arduino_sketch_spec.rb
│   │   ├── sketch_compiler_spec.rb
│   │   └── spec_helper.rb
│   ├── sim/
│   │   └── hello_world_spec.rb
│   └── spec.opts
├── test/
│   ├── hello_world_test/
│   │   ├── Makefile
│   │   └── hello_world.cpp
│   ├── test_array_processing.rb
│   ├── test_plugin_loading.rb
│   ├── test_translation_post_processing.rb
│   └── test_variable_processing.rb
└── website/
    ├── examples/
    │   ├── assembler_test.rb.html
    │   ├── gps_reader.rb.html
    │   ├── hello_world.rb.html
    │   └── serial_motor.rb.html
    ├── index.html
    ├── index.txt
    ├── javascripts/
    │   └── rounded_corners_lite.inc.js
    ├── stylesheets/
    │   ├── code.css
    │   └── screen.css
    └── template.rhtml
Download .txt
SYMBOL INDEX (599 symbols across 72 files)

FILE: lib/examples/add_hysteresis.rb
  class AddHysteresis (line 1) | class AddHysteresis < ArduinoSketch
    method loop (line 7) | def loop

FILE: lib/examples/basic_blink.rb
  class BasicBlink (line 1) | class BasicBlink < ArduinoSketch
    method loop (line 6) | def loop

FILE: lib/examples/blink_m_address_assignment.rb
  class BlinkMAddressAssignment (line 1) | class BlinkMAddressAssignment < ArduinoSketch
    method setup (line 32) | def setup
    method loop (line 38) | def loop
    method staging (line 48) | def staging
    method assign_address (line 69) | def assign_address
    method control_it (line 79) | def control_it
    method test_address (line 93) | def test_address

FILE: lib/examples/blink_m_hello.rb
  class BlinkMHello (line 1) | class BlinkMHello < ArduinoSketch
    method loop (line 7) | def loop

FILE: lib/examples/blink_m_multi.rb
  class BlinkMMulti (line 1) | class BlinkMMulti < ArduinoSketch
    method loop (line 25) | def loop
    method stop_and_fade (line 32) | def stop_and_fade(addr)
    method dance (line 45) | def dance

FILE: lib/examples/blink_with_serial.rb
  class BlinkWithSerial (line 1) | class BlinkWithSerial < ArduinoSketch
    method loop (line 10) | def loop

FILE: lib/examples/configure_pa_lcd_boot.rb
  class ConfigurePaLcdBoot (line 1) | class ConfigurePaLcdBoot < ArduinoSketch
    method loop (line 41) | def loop
    method set_custom_screen (line 51) | def set_custom_screen
    method set_cursor (line 66) | def set_cursor
    method change_boot_to_custom (line 80) | def change_boot_to_custom

FILE: lib/examples/debounce_methods.rb
  class DebounceMethods (line 1) | class DebounceMethods < ArduinoSketch
    method loop (line 15) | def loop
    method blink_twice (line 23) | def blink_twice
    method blink_three_times (line 29) | def blink_three_times
    method blink_three_times_basic (line 34) | def blink_three_times_basic
    method blink_with_a_twist (line 43) | def blink_with_a_twist

FILE: lib/examples/external_variable_fu.rb
  class ExternalVariableFu (line 1) | class ExternalVariableFu < ArduinoSketch
    method loop (line 22) | def loop

FILE: lib/examples/external_variables.rb
  class ExternalVariables (line 1) | class ExternalVariables < ArduinoSketch
    method loop (line 17) | def loop
    method setup (line 23) | def setup # special one time only method

FILE: lib/examples/first_sound.rb
  class FirstSound (line 1) | class FirstSound < ArduinoSketch
    method loop (line 7) | def loop
    method tone_out (line 14) | def tone_out(n)

FILE: lib/examples/frequency_generator.rb
  class FrequencyGenerator (line 1) | class FrequencyGenerator < ArduinoSketch
    method loop (line 7) | def loop
    method uh_oh (line 11) | def uh_oh(n)

FILE: lib/examples/hello_array.rb
  class HelloArray (line 1) | class HelloArray < ArduinoSketch
    method loop (line 18) | def loop

FILE: lib/examples/hello_array2.rb
  class HelloArray2 (line 1) | class HelloArray2 < ArduinoSketch
    method setup (line 35) | def setup
    method loop (line 108) | def loop

FILE: lib/examples/hello_array_eeprom.rb
  class HelloArrayEeprom (line 1) | class HelloArrayEeprom < ArduinoSketch
    method setup (line 27) | def setup
    method loop (line 55) | def loop

FILE: lib/examples/hello_clock.rb
  class HelloClock (line 1) | class HelloClock < ArduinoSketch
    method setup (line 37) | def setup
    method loop (line 45) | def loop
    method printlz (line 68) | def	printlz(w)
    method print_main (line 73) | def	print_main

FILE: lib/examples/hello_eeprom.rb
  class HelloEeprom (line 1) | class HelloEeprom < ArduinoSketch
    method loop (line 8) | def loop
    method printlz (line 45) | def	printlz(w)

FILE: lib/examples/hello_eeprom_lcdpa.rb
  class HelloEepromLcdpa (line 1) | class HelloEepromLcdpa < ArduinoSketch
    method setup (line 38) | def setup
    method loop (line 69) | def loop
    method clear_off_test (line 74) | def clear_off_test   # clears bottom two lines

FILE: lib/examples/hello_format_print.rb
  class HelloFormatPrint (line 1) | class HelloFormatPrint < ArduinoSketch
    method setup (line 40) | def setup
    method loop (line 44) | def loop
    method say_hello (line 54) | def say_hello
    method say_more (line 63) | def say_more # passing print strings to home and setxy (also works on ...
    method say_it_large (line 78) | def say_it_large

FILE: lib/examples/hello_lcd_charset.rb
  class HelloLcdCharset (line 1) | class HelloLcdCharset < ArduinoSketch
    method loop (line 21) | def loop

FILE: lib/examples/hello_pa_lcd.rb
  class HelloPaLcd (line 1) | class HelloPaLcd < ArduinoSketch
    method setup (line 17) | def setup
    method loop (line 25) | def loop
    method say_hello (line 31) | def say_hello
    method say_more (line 39) | def say_more # passing print strings to home and setxy (also works on ...
    method say_it_large (line 47) | def say_it_large

FILE: lib/examples/hello_servos.rb
  class HelloServos (line 1) | class HelloServos < ArduinoSketch
    method loop (line 9) | def loop
    method song_sheet_two (line 13) | def song_sheet_two
    method a (line 45) | def a
    method b (line 52) | def b
    method c (line 59) | def c
    method d (line 66) | def d
    method e (line 73) | def e
    method home (line 83) | def home(s)

FILE: lib/examples/hello_spectra_sound.rb
  class HelloSpectraSound (line 1) | class HelloSpectraSound < ArduinoSketch
    method setup (line 16) | def setup
    method loop (line 24) | def loop

FILE: lib/examples/hello_world.rb
  class HelloWorld (line 1) | class HelloWorld < ArduinoSketch
    method loop (line 5) | def loop

FILE: lib/examples/hello_xbee.rb
  class HelloXbee (line 1) | class HelloXbee < ArduinoSketch
    method loop (line 6) | def loop

FILE: lib/examples/hysteresis_duel.rb
  class HysteresisDuel (line 1) | class HysteresisDuel < ArduinoSketch
    method setup (line 17) | def setup
    method loop (line 24) | def loop

FILE: lib/examples/i2c_with_clock_chip.rb
  class I2cWithClockChip (line 1) | class I2cWithClockChip < ArduinoSketch
    method loop (line 39) | def loop
    method printlz (line 109) | def	printlz(w)
    method print_hexbyte (line 114) | def	print_hexbyte(w)
    method clear_bottom_line (line 119) | def clear_bottom_line

FILE: lib/examples/midi_beat_box.rb
  class MidiBeatBox (line 1) | class MidiBeatBox < ArduinoSketch
    method setup (line 12) | def setup
    method loop (line 16) | def loop
    method first (line 26) | def first
    method second (line 48) | def second
    method third (line 60) | def third
    method play (line 73) | def play(one, two, three)

FILE: lib/examples/midi_scales.rb
  class MidiScales (line 1) | class MidiScales < ArduinoSketch
    method setup (line 26) | def setup
    method loop (line 30) | def loop
    method change_tone (line 39) | def change_tone
    method change_pressure (line 45) | def change_pressure
    method change_channels (line 51) | def change_channels
    method read_sensor_one (line 57) | def read_sensor_one
    method read_sensor_two (line 63) | def read_sensor_two
    method read_sensor_three (line 69) | def read_sensor_three
    method pre_play (line 75) | def pre_play(current_note, last_note, channel) # warning, don't use la...
    method play (line 83) | def play(chan, note, pressure)
    method play_with_no_delay (line 89) | def play_with_no_delay(chan, note, pressure) # note is not turned off

FILE: lib/examples/motor_knob.rb
  class MotorKnob (line 1) | class MotorKnob < ArduinoSketch
    method loop (line 22) | def loop

FILE: lib/examples/servo_buttons.rb
  class ServoButtons (line 1) | class ServoButtons < ArduinoSketch
    method loop (line 12) | def loop
    method check_buttons (line 17) | def check_buttons

FILE: lib/examples/servo_calibrate_continuous.rb
  class ServoCalibrateContinuous (line 1) | class ServoCalibrateContinuous < ArduinoSketch
    method loop (line 50) | def loop
    method delay_servo (line 85) | def delay_servo(t)

FILE: lib/examples/servo_throttle.rb
  class ServoThrottle (line 1) | class ServoThrottle < ArduinoSketch
    method loop (line 19) | def loop
    method servo_status (line 29) | def servo_status

FILE: lib/examples/software_serial.rb
  class SoftwareSerial (line 1) | class SoftwareSerial < ArduinoSketch
    method loop (line 6) | def loop

FILE: lib/examples/sparkfun_lcd.rb
  class SparkfunLcd (line 1) | class SparkfunLcd < ArduinoSketch
    method loop (line 16) | def loop
    method say_hello (line 23) | def say_hello
    method say_ruby (line 31) | def	say_ruby
    method check_buttons (line 40) | def check_buttons

FILE: lib/examples/spectra_soft_pot.rb
  class SpectraSoftPot (line 1) | class SpectraSoftPot < ArduinoSketch
    method setup (line 15) | def setup
    method loop (line 23) | def loop

FILE: lib/examples/times_method.rb
  class TimesMethod (line 1) | class TimesMethod < ArduinoSketch
    method loop (line 3) | def loop

FILE: lib/examples/toggle.rb
  class Toggle (line 1) | class Toggle < ArduinoSketch
    method loop (line 5) | def loop

FILE: lib/examples/twitter.rb
  class Twitter (line 1) | class Twitter < ArduinoSketch
    method loop (line 44) | def loop

FILE: lib/examples/two_wire.rb
  class TwoWire (line 1) | class TwoWire < ArduinoSketch
    method loop (line 7) | def loop

FILE: lib/libraries/Wire/utility/twi.c
  function twi_init (line 61) | void twi_init(void)
  function twi_setAddress (line 103) | void twi_setAddress(uint8_t address)
  function twi_readFrom (line 118) | uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length)
  function twi_writeTo (line 167) | uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint...
  function twi_transmit (line 216) | uint8_t twi_transmit(uint8_t* data, uint8_t length)
  function twi_attachSlaveRxEvent (line 245) | void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) )
  function twi_attachSlaveTxEvent (line 256) | void twi_attachSlaveTxEvent( void (*function)(void) )
  function twi_reply (line 267) | void twi_reply(uint8_t ack)
  function twi_stop (line 283) | void twi_stop(void)
  function twi_releaseBus (line 304) | void twi_releaseBus(void)
  function SIGNAL (line 313) | SIGNAL(SIG_2WIRE_SERIAL)

FILE: lib/plugins/bitwise_ops.rb
  class BitwiseOps (line 1) | class BitwiseOps < ArduinoPlugin

FILE: lib/plugins/blink.rb
  class Blink (line 1) | class Blink < ArduinoPlugin

FILE: lib/plugins/debug_output_to_lcd.rb
  class DebugOutputToLcd (line 1) | class DebugOutputToLcd < ArduinoPlugin

FILE: lib/plugins/midi.rb
  class Midi (line 1) | class Midi < ArduinoPlugin

FILE: lib/plugins/parallax_ping.rb
  class ParallaxPing (line 1) | class ParallaxPing < ArduinoPlugin

FILE: lib/plugins/servo_pulse.rb
  class ServoPulse (line 1) | class ServoPulse < ArduinoPlugin

FILE: lib/rad.rb
  type Rad (line 1) | module Rad

FILE: lib/rad/arduino_plugin.rb
  class ArduinoPlugin (line 45) | class ArduinoPlugin
    method initialize (line 47) | def initialize #:nodoc:
    method include_wire (line 69) | def include_wire
    method add_to_setup (line 74) | def add_to_setup(*args)
    method plugin_directives (line 83) | def plugin_directives(*args)
    method external_variables (line 92) | def external_variables(*args)
    method add_blink_m_struct (line 104) | def add_blink_m_struct
    method add_blink_m_struct (line 113) | def self.add_blink_m_struct
    method add_debounce_struct (line 122) | def add_debounce_struct
    method add_servo_struct (line 135) | def add_servo_struct
    method add_debounce_struct (line 149) | def self.add_debounce_struct
    method add_servo_struct (line 162) | def self.add_servo_struct
    method add_sensor_struct (line 176) | def self.add_sensor_struct
    method add_spectra_struct (line 185) | def self.add_spectra_struct
    method check_for_plugin_use (line 198) | def self.check_for_plugin_use(sketch_string, plugin_string, file_name)...
    method process (line 224) | def self.process(plugin_string)
    method add_struct (line 241) | def add_struct(struct)

FILE: lib/rad/arduino_sketch.rb
  class ArduinoSketch (line 155) | class ArduinoSketch
    method initialize (line 164) | def initialize #:nodoc:
    method array (line 204) | def array(arg)
    method define (line 231) | def define(arg)
    method output_pin (line 272) | def output_pin(num, opts={})
    method input_pin (line 351) | def input_pin(num, opts={})
    method input_pins (line 394) | def input_pins(nums)
    method add (line 399) | def add(st) #:nodoc:
    method serial_begin (line 409) | def serial_begin(opts={})
    method formatted_print (line 416) | def formatted_print(opts={})
    method compose_setup (line 436) | def compose_setup #:nodoc: also composes headers and signatures
    method assembler (line 568) | def assembler(name, signature, code)
    method pre_process (line 584) | def self.pre_process(sketch_string) #:nodoc:
    method add_to_setup (line 599) | def self.add_to_setup(meth)
    method post_process_ruby_to_c_methods (line 604) | def self.post_process_ruby_to_c_methods(e)
    method comment_box (line 618) | def comment_box( content ) #:nodoc:

FILE: lib/rad/darwin_installer.rb
  class DarwinInstaller (line 1) | class DarwinInstaller
    method install! (line 2) | def self.install!

FILE: lib/rad/generators/makefile/makefile.rb
  class Makefile (line 4) | class Makefile
    method compose_for_sketch (line 8) | def compose_for_sketch(build_dir)
    method hardware_params (line 27) | def hardware_params
    method software_params (line 32) | def software_params

FILE: lib/rad/hardware_library.rb
  class HardwareLibrary (line 1) | class HardwareLibrary < ArduinoSketch
    method initialize (line 3) | def initialize
    method software_serial (line 8) | def software_serial(rx, tx, opts={})
    method pa_lcd_setup (line 53) | def pa_lcd_setup(num, opts)
    method swser_LCDpa (line 65) | def swser_LCDpa(tx, opts={})
    method sf_lcd_setup (line 185) | def sf_lcd_setup(num, opts)
    method swser_LCDsf (line 196) | def swser_LCDsf(tx, opts={})
    method loop_timer (line 299) | def loop_timer(opts={}) # loop timer methods #
    method servo_setup (line 330) | def servo_setup(num, opts)
    method servo (line 351) | def servo(pin, opts={}) # servo motor routines #
    method twowire_stepper (line 412) | def twowire_stepper(pin1, pin2, opts={}) # servo motor routines #
    method fourwire_stepper (line 452) | def fourwire_stepper( pin1, pin2, pin3, pin4, opts={}) # servo motor r...
    method frequency_timer (line 494) | def frequency_timer(pin, opts={}) # frequency timer routines
    method one_wire (line 548) | def one_wire(pin, opts={})
    method two_wire (line 593) | def two_wire (pin, opts={}) # i2c Two-Wire
    method ethernet (line 663) | def ethernet(pin, opts={})
    method i2c_eeprom (line 678) | def i2c_eeprom(pin, opts={}) # i2c serial eeprom routines #
    method ds1307 (line 718) | def ds1307(pin, opts={}) # DS1307 real time clock routines routines
    method serial_boilerplate (line 758) | def serial_boilerplate #:nodoc:

FILE: lib/rad/linux_installer.rb
  class LinuxInstaller (line 1) | class LinuxInstaller
    method install! (line 4) | def self.install!
    method check_or_install_package (line 41) | def self.check_or_install_package(package_name)
    method check_or_nag_package (line 51) | def self.check_or_nag_package(package_name, custom_msg = nil)
    method check_or_remove_package (line 66) | def self.check_or_remove_package(package_name)
    method check_or_warn_for_usb_driver (line 78) | def self.check_or_warn_for_usb_driver
    method check_or_install_arduino (line 93) | def self.check_or_install_arduino

FILE: lib/rad/progressbar.rb
  class ProgressBar (line 12) | class ProgressBar
    method initialize (line 15) | def initialize (title, total, out = STDERR)
    method fmt_bar (line 38) | def fmt_bar
    method fmt_percentage (line 45) | def fmt_percentage
    method fmt_stat (line 49) | def fmt_stat
    method fmt_stat_for_file_transfer (line 53) | def fmt_stat_for_file_transfer
    method fmt_title (line 61) | def fmt_title
    method convert_bytes (line 65) | def convert_bytes (bytes)
    method transfer_rate (line 77) | def transfer_rate
    method bytes (line 82) | def bytes
    method format_time (line 86) | def format_time (t)
    method eta (line 95) | def eta
    method elapsed (line 105) | def elapsed
    method eol (line 110) | def eol
    method do_percentage (line 114) | def do_percentage
    method get_width (line 122) | def get_width
    method show (line 139) | def show
    method show_if_needed (line 160) | def show_if_needed
    method clear (line 177) | def clear
    method finish (line 183) | def finish
    method finished? (line 189) | def finished?
    method file_transfer_mode (line 193) | def file_transfer_mode
    method format= (line 197) | def format= (format)
    method format_arguments= (line 201) | def format_arguments= (arguments)
    method halt (line 205) | def halt
    method inc (line 210) | def inc (step = 1)
    method set (line 217) | def set (count)
    method inspect (line 226) | def inspect
  class ReversedProgressBar (line 231) | class ReversedProgressBar < ProgressBar
    method do_percentage (line 232) | def do_percentage

FILE: lib/rad/rad_processor.rb
  class RADProcessor (line 4) | class RADProcessor < RubyToAnsiC
    method translator (line 6) | def self.translator
    method process_iasgn (line 29) | def process_iasgn(exp)
    method process_ivar (line 35) | def process_ivar(exp)
    method process_iter (line 40) | def process_iter(exp)
    method process_lasgn (line 81) | def process_lasgn(exp)
    method process_str (line 118) | def process_str(exp)

FILE: lib/rad/rad_rewriter.rb
  class RADRewriter (line 3) | class RADRewriter < Rewriter
    method process_iter (line 5) | def process_iter(exp)

FILE: lib/rad/rad_type_checker.rb
  class RADTypeChecker (line 3) | class RADTypeChecker < TypeChecker
    method process_const (line 5) | def process_const(exp)

FILE: lib/rad/sim/arduino_sketch.rb
  class ArduinoSketch (line 6) | class ArduinoSketch
    method initialize (line 9) | def initialize
    method output_pin (line 13) | def self.output_pin(num, opts)
    method loop (line 28) | def loop
    method digitalWrite (line 31) | def digitalWrite( pin, value )
    method delay (line 36) | def delay( millis )
  class Pin (line 49) | class Pin
    method initialize (line 52) | def initialize num, opts

FILE: lib/rad/sketch_compiler.rb
  class SketchCompiler (line 12) | class SketchCompiler
    method initialize (line 15) | def initialize path_to_sketch
    method parent_dir (line 23) | def parent_dir
    method build_dir (line 27) | def build_dir
    method create_build_dir! (line 31) | def create_build_dir! optional_path_prefix=nil
    method process_constants (line 36) | def process_constants
    method sketch_methods (line 43) | def sketch_methods

FILE: lib/rad/tasks/build_and_make.rake
  function run_tests (line 10) | def run_tests(sketch, type)
  function constantize (line 204) | def constantize(camel_cased_word)

FILE: lib/rad/variable_processing.rb
  type ExternalVariableProcessing (line 1) | module ExternalVariableProcessing
    function process_external_vars (line 9) | def process_external_vars(klass)
    function pre_process_vars (line 24) | def pre_process_vars(name, var)
    function translate_variables (line 68) | def translate_variables(name, type = nil, value = nil)
    function post_process_vars (line 114) | def post_process_vars(name, type, value = nil)
    function post_process_arrays (line 120) | def post_process_arrays(name, var)
    function check_variable_type (line 129) | def check_variable_type(type)
    function c_type (line 135) | def c_type(typ)

FILE: lib/rad/version.rb
  type Rad (line 1) | module Rad #:nodoc:
    type VERSION (line 2) | module VERSION #:nodoc:

FILE: setup.rb
  type Enumerable (line 12) | module Enumerable
  function read (line 18) | def File.read(fname)
  type Errno (line 26) | module Errno
    class ENOTEMPTY (line 27) | class ENOTEMPTY
  function binread (line 33) | def File.binread(fname)
  function dir? (line 40) | def File.dir?(path)
  class ConfigTable (line 45) | class ConfigTable
    method initialize (line 49) | def initialize(rbconfig)
    method verbose? (line 65) | def verbose?
    method no_harm? (line 71) | def no_harm?
    method [] (line 75) | def [](key)
    method []= (line 79) | def []=(key, val)
    method names (line 83) | def names
    method each (line 87) | def each(&block)
    method key? (line 91) | def key?(name)
    method lookup (line 95) | def lookup(name)
    method add (line 99) | def add(item)
    method remove (line 104) | def remove(name)
    method load_script (line 111) | def load_script(path, inst = nil)
    method savefile (line 117) | def savefile
    method load_savefile (line 121) | def load_savefile
    method save (line 132) | def save
    method load_standard_entries (line 141) | def load_standard_entries
    method standard_entries (line 147) | def standard_entries(rbconfig)
    method load_multipackage_entries (line 260) | def load_multipackage_entries
    method multipackage_entries (line 266) | def multipackage_entries
    method fixup (line 295) | def fixup
    method parse_opt (line 304) | def parse_opt(opt)
    method dllext (line 309) | def dllext
    method value_config? (line 313) | def value_config?(name)
    class Item (line 317) | class Item
      method initialize (line 318) | def initialize(name, template, default, desc)
      method help_opt (line 332) | def help_opt
      method value? (line 336) | def value?
      method value (line 340) | def value
      method resolve (line 344) | def resolve(table)
      method set (line 348) | def set(val)
      method check (line 354) | def check(val)
    class BoolItem (line 360) | class BoolItem < Item
      method config_type (line 361) | def config_type
      method help_opt (line 365) | def help_opt
      method check (line 371) | def check(val)
    class PathItem (line 382) | class PathItem < Item
      method config_type (line 383) | def config_type
      method check (line 389) | def check(path)
    class ProgramItem (line 395) | class ProgramItem < Item
      method config_type (line 396) | def config_type
    class SelectItem (line 401) | class SelectItem < Item
      method initialize (line 402) | def initialize(name, selection, default, desc)
      method config_type (line 407) | def config_type
      method check (line 413) | def check(val)
    class ExecItem (line 421) | class ExecItem < Item
      method initialize (line 422) | def initialize(name, selection, desc, &block)
      method config_type (line 428) | def config_type
      method value? (line 432) | def value?
      method resolve (line 436) | def resolve(table)
      method evaluate (line 442) | def evaluate(val, table)
    class PackageSelectionItem (line 451) | class PackageSelectionItem < Item
      method initialize (line 452) | def initialize(name, template, default, help_default, desc)
      method config_type (line 459) | def config_type
      method check (line 465) | def check(val)
    class MetaConfigEnvironment (line 473) | class MetaConfigEnvironment
      method initialize (line 474) | def initialize(config, installer)
      method config_names (line 479) | def config_names
      method config? (line 483) | def config?(name)
      method bool_config? (line 487) | def bool_config?(name)
      method path_config? (line 491) | def path_config?(name)
      method value_config? (line 495) | def value_config?(name)
      method add_config (line 499) | def add_config(item)
      method add_bool_config (line 503) | def add_bool_config(name, default, desc)
      method add_path_config (line 507) | def add_path_config(name, default, desc)
      method set_config_default (line 511) | def set_config_default(name, default)
      method remove_config (line 515) | def remove_config(name)
      method packages (line 520) | def packages
      method declare_packages (line 526) | def declare_packages(list)
  type FileOperations (line 536) | module FileOperations
    function mkdir_p (line 538) | def mkdir_p(dirname, prefix = nil)
    function rm_f (line 555) | def rm_f(path)
    function rm_rf (line 561) | def rm_rf(path)
    function remove_tree (line 567) | def remove_tree(path)
    function remove_tree0 (line 577) | def remove_tree0(path)
    function move_file (line 597) | def move_file(src, dest)
    function force_remove_file (line 610) | def force_remove_file(path)
    function remove_file (line 617) | def remove_file(path)
    function install (line 622) | def install(from, dest, mode, prefix = nil)
    function diff? (line 648) | def diff?(new_content, path)
    function command (line 653) | def command(*args)
    function ruby (line 659) | def ruby(*args)
    function make (line 663) | def make(task = nil)
    function extdir? (line 667) | def extdir?(dir)
    function files_of (line 671) | def files_of(dir)
    function directories_of (line 679) | def directories_of(dir)
  type HookScriptAPI (line 689) | module HookScriptAPI
    function get_config (line 691) | def get_config(key)
    function set_config (line 698) | def set_config(key, val)
    function curr_srcdir (line 706) | def curr_srcdir
    function curr_objdir (line 710) | def curr_objdir
    function srcfile (line 714) | def srcfile(path)
    function srcexist? (line 718) | def srcexist?(path)
    function srcdirectory? (line 722) | def srcdirectory?(path)
    function srcfile? (line 726) | def srcfile?(path)
    function srcentries (line 730) | def srcentries(path = '.')
    function srcfiles (line 736) | def srcfiles(path = '.')
    function srcdirectories (line 742) | def srcdirectories(path = '.')
  class ToplevelInstaller (line 751) | class ToplevelInstaller
    method invoke (line 767) | def ToplevelInstaller.invoke
    method multipackage? (line 776) | def ToplevelInstaller.multipackage?
    method load_rbconfig (line 780) | def ToplevelInstaller.load_rbconfig
    method initialize (line 791) | def initialize(ardir_root, config)
    method config (line 798) | def config(key)
    method inspect (line 802) | def inspect
    method invoke (line 806) | def invoke
    method run_metaconfigs (line 830) | def run_metaconfigs
    method init_installers (line 834) | def init_installers
    method srcdir_root (line 842) | def srcdir_root
    method objdir_root (line 846) | def objdir_root
    method relpath (line 850) | def relpath
    method parsearg_global (line 858) | def parsearg_global
    method valid_task? (line 884) | def valid_task?(t)
    method valid_task_re (line 888) | def valid_task_re
    method parsearg_no_options (line 892) | def parsearg_no_options
    method parsearg_config (line 905) | def parsearg_config
    method parsearg_install (line 931) | def parsearg_install
    method print_usage (line 948) | def print_usage(out)
    method exec_config (line 990) | def exec_config
    method exec_setup (line 995) | def exec_setup
    method exec_install (line 999) | def exec_install
    method exec_test (line 1003) | def exec_test
    method exec_show (line 1007) | def exec_show
    method exec_clean (line 1013) | def exec_clean
    method exec_distclean (line 1017) | def exec_distclean
  class ToplevelInstallerMulti (line 1024) | class ToplevelInstallerMulti < ToplevelInstaller
    method initialize (line 1028) | def initialize(ardir_root, config)
    method run_metaconfigs (line 1035) | def run_metaconfigs
    method packages= (line 1044) | def packages=(list)
    method init_installers (line 1053) | def init_installers
    method extract_selection (line 1068) | def extract_selection(list)
    method print_usage (line 1076) | def print_usage(f)
    method exec_config (line 1087) | def exec_config
    method exec_setup (line 1094) | def exec_setup
    method exec_install (line 1100) | def exec_install
    method exec_test (line 1106) | def exec_test
    method exec_clean (line 1112) | def exec_clean
    method exec_distclean (line 1119) | def exec_distclean
    method each_selected_installers (line 1130) | def each_selected_installers
    method run_hook (line 1141) | def run_hook(id)
    method verbose? (line 1146) | def verbose?
    method no_harm? (line 1151) | def no_harm?
  class Installer (line 1158) | class Installer
    method initialize (line 1165) | def initialize(config, srcroot, objroot)
    method inspect (line 1172) | def inspect
    method noop (line 1176) | def noop(rel)
    method srcdir_root (line 1183) | def srcdir_root
    method objdir_root (line 1187) | def objdir_root
    method relpath (line 1191) | def relpath
    method verbose? (line 1200) | def verbose?
    method no_harm? (line 1205) | def no_harm?
    method verbose_off (line 1209) | def verbose_off
    method exec_config (line 1222) | def exec_config
    method config_dir_ext (line 1229) | def config_dir_ext(rel)
    method extconf (line 1237) | def extconf
    method exec_setup (line 1245) | def exec_setup
    method setup_dir_bin (line 1249) | def setup_dir_bin(rel)
    method setup_dir_ext (line 1257) | def setup_dir_ext(rel)
    method update_shebang_line (line 1265) | def update_shebang_line(path)
    method new_shebang (line 1287) | def new_shebang(old)
    method open_atomic_writer (line 1298) | def open_atomic_writer(path, &block)
    class Shebang (line 1308) | class Shebang
      method load (line 1309) | def Shebang.load(path)
      method parse (line 1318) | def Shebang.parse(line)
      method initialize (line 1323) | def initialize(cmd, args = [])
      method to_s (line 1331) | def to_s
    method exec_install (line 1340) | def exec_install
    method install_dir_bin (line 1345) | def install_dir_bin(rel)
    method install_dir_lib (line 1349) | def install_dir_lib(rel)
    method install_dir_ext (line 1353) | def install_dir_ext(rel)
    method install_dir_data (line 1360) | def install_dir_data(rel)
    method install_dir_conf (line 1364) | def install_dir_conf(rel)
    method install_dir_man (line 1370) | def install_dir_man(rel)
    method install_files (line 1374) | def install_files(list, dest, mode)
    method libfiles (line 1381) | def libfiles
    method rubyextentions (line 1385) | def rubyextentions(dir)
    method targetfiles (line 1393) | def targetfiles
    method mapdir (line 1397) | def mapdir(ents)
    method existfiles (line 1415) | def existfiles
    method hookfiles (line 1419) | def hookfiles
    method glob_select (line 1425) | def glob_select(pat, ents)
    method glob_reject (line 1430) | def glob_reject(pats, ents)
    method globs2re (line 1442) | def globs2re(pats)
    method exec_test (line 1454) | def exec_test
    method exec_clean (line 1474) | def exec_clean
    method clean_dir_ext (line 1486) | def clean_dir_ext(rel)
    method exec_distclean (line 1495) | def exec_distclean
    method distclean_dir_ext (line 1504) | def distclean_dir_ext(rel)
    method exec_task_traverse (line 1517) | def exec_task_traverse(task)
    method traverse (line 1529) | def traverse(task, rel, mid)
    method dive_into (line 1540) | def dive_into(rel)
    method run_hook (line 1555) | def run_hook(id)
  class SetupError (line 1570) | class SetupError < StandardError; end
  function setup_rb_error (line 1572) | def setup_rb_error(msg)

FILE: spec/examples/hello_world.rb
  class HelloWorld (line 3) | class HelloWorld < ArduinoSketch
    method loop (line 5) | def loop

FILE: spec/examples/serial_motor.rb
  class SerialMotor (line 5) | class SerialMotor < ArduinoSketch
    method loop (line 9) | def loop

FILE: test/hello_world_test/hello_world.cpp
  function setup (line 7) | void setup() {
  function main (line 11) | int main() {
  function loop (line 18) | void loop() {

FILE: test/test_array_processing.rb
  class TestArrayProcessing (line 12) | class TestArrayProcessing < Test::Unit::TestCase
    method setup (line 14) | def setup
    method test_int_array (line 21) | def test_int_array
    method test_int_array_with_semi (line 29) | def test_int_array_with_semi
    method test_int_array_with_assignment (line 37) | def test_int_array_with_assignment
    method test_int_array_with_assignment_and_semi (line 45) | def test_int_array_with_assignment_and_semi
    method test_unsigned_int_array (line 53) | def test_unsigned_int_array
    method test_unsigned_int_array_with_assignment (line 61) | def test_unsigned_int_array_with_assignment
    method test_define_numbers (line 71) | def test_define_numbers
    method test_define_numbers_type (line 79) | def test_define_numbers_type
    method test_define_value_type_long_via_gvar (line 87) | def test_define_value_type_long_via_gvar
    method test_define_string (line 95) | def test_define_string
    method test_define_string_type (line 103) | def test_define_string_type
    method test_define_string_type__via_gvar (line 111) | def test_define_string_type__via_gvar
    method test_define_stings_with_spaces (line 119) | def test_define_stings_with_spaces
    method test_define_stings_with_spaces_type (line 127) | def test_define_stings_with_spaces_type
    method test_define_stings_with_spaces_type_via_gvar (line 135) | def test_define_stings_with_spaces_type_via_gvar
    method test_define_float (line 143) | def test_define_float
    method test_define_float_type (line 151) | def test_define_float_type
    method test_define_float_type_via_gvar (line 160) | def test_define_float_type_via_gvar

FILE: test/test_plugin_loading.rb
  class TestPluginLoading (line 22) | class TestPluginLoading < Test::Unit::TestCase
    method setup (line 27) | def setup
    method test_int (line 124) | def test_int
    method test_two (line 134) | def test_two

FILE: test/test_translation_post_processing.rb
  class TranslationTesting (line 18) | class TranslationTesting < ArduinoSketch
    method one (line 20) | def one
    method two (line 24) | def two
    method three (line 29) | def three
    method four (line 35) | def four
    method five (line 41) | def five
    method six (line 46) | def six
    method seven (line 51) | def seven(int)
    method eight (line 56) | def eight(str)
    method nine (line 61) | def nine
  class TestTranslationPostProcessing (line 72) | class TestTranslationPostProcessing < Test::Unit::TestCase
    method setup (line 77) | def setup
    method test_int (line 88) | def test_int
    method test_bool (line 96) | def test_bool
    method test_long (line 104) | def test_long
    method test_trans_one (line 112) | def test_trans_one
    method test_trans_two (line 120) | def test_trans_two
    method test_trans_three (line 128) | def test_trans_three
    method test_trans_four (line 137) | def test_trans_four
    method test_trans_five (line 144) | def test_trans_five
    method test_trans_six (line 151) | def test_trans_six
    method test_trans_seven (line 158) | def test_trans_seven
    method test_trans_eight (line 165) | def test_trans_eight
    method test_trans_nine (line 172) | def test_trans_nine

FILE: test/test_variable_processing.rb
  class TestVariableProcessing (line 15) | class TestVariableProcessing < Test::Unit::TestCase
    method setup (line 17) | def setup
    method test_int_as_int (line 26) | def test_int_as_int
    method test_string_as_int (line 34) | def test_string_as_int
    method test_float_as_float (line 42) | def test_float_as_float
    method test_string_as_float (line 50) | def test_string_as_float
    method test_byte (line 58) | def test_byte # would this to return hex
    method test_byte_with_string_input (line 66) | def test_byte_with_string_input
    method test_string (line 74) | def test_string
    method test_int_with_type (line 82) | def test_int_with_type
    method test_odd_name (line 90) | def test_odd_name
    method test_int_with_type_two (line 98) | def test_int_with_type_two
    method test_int_with_long (line 106) | def test_int_with_long
    method test_int_with_byte (line 114) | def test_int_with_byte
    method test_int_with_unsigned_int (line 122) | def test_int_with_unsigned_int
    method test_int_with_unsigned_long (line 130) | def test_int_with_unsigned_long
    method test_int_with_short_int (line 138) | def test_int_with_short_int
    method test_int_with_unsigned_short_int (line 146) | def test_int_with_unsigned_short_int
    method test_float_with_type (line 154) | def test_float_with_type
    method test_true (line 162) | def test_true
    method test_false (line 170) | def test_false
    method test_negative_int_string (line 178) | def test_negative_int_string
    method test_negative_float_string (line 186) | def test_negative_float_string
    method test_negative_larger_float_string (line 194) | def test_negative_larger_float_string
    method test_negative_long_string (line 202) | def test_negative_long_string
    method test_negative_float_string_two (line 210) | def test_negative_float_string_two
    method test_negative_interter_string (line 218) | def test_negative_interter_string
    method test_dash_string (line 226) | def test_dash_string

FILE: website/javascripts/rounded_corners_lite.inc.js
  function curvyCorners (line 38) | function curvyCorners()
  function curvyObject (line 54) | function curvyObject()
  function insertAfter (line 190) | function insertAfter(parent, node, referenceNode)
  function BlendColour (line 192) | function BlendColour(Col1, Col2, Col1Fraction)
  function IntToHex (line 194) | function IntToHex(strNum)
  function MakeHex (line 196) | function MakeHex(x)
  function pixelFraction (line 204) | function pixelFraction(x, y, r)
  function rgb2Hex (line 221) | function rgb2Hex(rgbColour)
  function rgb2Array (line 225) | function rgb2Array(rgbColour)
  function setOpacity (line 227) | function setOpacity(obj, opacity)
  function inArray (line 239) | function inArray(array, value)
  function inArrayKey (line 242) | function inArrayKey(array, value)
  function addEvent (line 245) | function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListene...
  function removeEvent (line 249) | function removeEvent(obj, evType, fn, useCapture){ if (obj.removeEventLi...
  function format_colour (line 251) | function format_colour(colour)
  function get_style (line 261) | function get_style(obj, property, propertyNS)
  function getElementsByClass (line 275) | function getElementsByClass(searchClass, node, tag)
  function newCurvyError (line 283) | function newCurvyError(errorMessage)
Condensed preview — 114 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (419K chars).
[
  {
    "path": ".gitignore",
    "chars": 99,
    "preview": ".DS_Store\nbin/.DS_Store\nlib/.DS_Store\nlib/libraries/.DS_Store\nlib/rad/.DS_Store\nlib/libraries/*/*.*"
  },
  {
    "path": "History.txt",
    "chars": 3707,
    "preview": "== 0.3.0 2008-09-22\n* Pushing to rubyforge.. \n\t- added rad install arduino\n\t- added rad test arduino\n\n== 0.2.5 2008-07-2"
  },
  {
    "path": "License.txt",
    "chars": 15167,
    "preview": "\n                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\nCopyright (C) 1989, 1991 Fr"
  },
  {
    "path": "Manifest.txt",
    "chars": 4328,
    "preview": "History.txt\nLicense.txt\nManifest.txt\nREADME.rdoc\nRakefile\nbin/rad\nlib/examples/add_hysteresis.rb\nlib/examples/basic_blin"
  },
  {
    "path": "README.markdown",
    "chars": 2212,
    "preview": "# Welcome to RAD (Ruby Arduino Development)\n\nRAD is a framework for programming the Arduino physcial computing platform "
  },
  {
    "path": "Rakefile",
    "chars": 4598,
    "preview": "require 'rubygems'\nrequire 'rake'\nrequire 'rake/clean'\nrequire 'rake/testtask'\nrequire 'rake/packagetask'\nrequire 'rake/"
  },
  {
    "path": "bin/rad",
    "chars": 10642,
    "preview": "#!/usr/bin/env ruby\n\nbegin\n  require 'rubygems'\nrescue LoadError\n  # no rubygems to load, so we fail silently\nend\n\nrequi"
  },
  {
    "path": "lib/examples/add_hysteresis.rb",
    "chars": 237,
    "preview": "class AddHysteresis < ArduinoSketch\n  \n  input_pin 3, :as => :sensor\n  output_pin 13, :as => :led\n\n\n  def loop\n    readi"
  },
  {
    "path": "lib/examples/basic_blink.rb",
    "chars": 154,
    "preview": "class BasicBlink < ArduinoSketch\n  # hello world (uncomment to run)\n  \n  output_pin 13, :as => :led\n  \n  def loop\n    bl"
  },
  {
    "path": "lib/examples/blink_m_address_assignment.rb",
    "chars": 2710,
    "preview": "class BlinkMAddressAssignment < ArduinoSketch\n\n  # want to use more than one blink m?\n  # since each blink m arrives wit"
  },
  {
    "path": "lib/examples/blink_m_hello.rb",
    "chars": 188,
    "preview": "class BlinkMHello < ArduinoSketch\n\n  # just a scaffolding for blink_m_demo \n\n  output_pin 19, :as => :wire, :device => :"
  },
  {
    "path": "lib/examples/blink_m_multi.rb",
    "chars": 1829,
    "preview": "class BlinkMMulti < ArduinoSketch\n\n  # demonstrate control of individual blinkms\n  # this assumes the leds have been ass"
  },
  {
    "path": "lib/examples/blink_with_serial.rb",
    "chars": 233,
    "preview": "class BlinkWithSerial < ArduinoSketch\n  \n  # hello world (uncomment to run)\n  @i  = \"0, long\"\n  \n  output_pin 13, :as =>"
  },
  {
    "path": "lib/examples/configure_pa_lcd_boot.rb",
    "chars": 2342,
    "preview": "class ConfigurePaLcdBoot < ArduinoSketch\n  \n## important!  \n## most pa_lcd rates are set to 9200, but there are some new"
  },
  {
    "path": "lib/examples/debounce_methods.rb",
    "chars": 1389,
    "preview": "class DebounceMethods < ArduinoSketch\n  \n  output_pin 13, :as => :led \n  input_pin 6, :as => :button_one, :device => :bu"
  },
  {
    "path": "lib/examples/external_variable_fu.rb",
    "chars": 405,
    "preview": "class ExternalVariableFu < ArduinoSketch\n  \n  @one = int\n  @two = long\n  @three = unsigned\n  @four = short\n  @five = byt"
  },
  {
    "path": "lib/examples/external_variables.rb",
    "chars": 463,
    "preview": "class ExternalVariables < ArduinoSketch\n\n  define \"KOOL 10\"\n  define \"TRUE 1\"\n  define \"COMMENT true\"\n  define \"DS1307_C"
  },
  {
    "path": "lib/examples/first_sound.rb",
    "chars": 502,
    "preview": "class FirstSound < ArduinoSketch\n\n\n\noutput_pin 11, :as => :myTone, :device => :freq_out, :frequency => 100 # frequency r"
  },
  {
    "path": "lib/examples/frequency_generator.rb",
    "chars": 602,
    "preview": "class FrequencyGenerator < ArduinoSketch\n  \n  # need explaination\n  \n  output_pin 11, :as => :myTone, :device => :freq_o"
  },
  {
    "path": "lib/examples/hello_array.rb",
    "chars": 974,
    "preview": "class HelloArray < ArduinoSketch\n\n # still working this out...\n # for example, new instance style array declaration nami"
  },
  {
    "path": "lib/examples/hello_array2.rb",
    "chars": 2525,
    "preview": "class HelloArray2 < ArduinoSketch\n\n   # ----------------------------------------------------------------------\n   #    C"
  },
  {
    "path": "lib/examples/hello_array_eeprom.rb",
    "chars": 1693,
    "preview": "class HelloArrayEeprom < ArduinoSketch\n\n   # ----------------------------------------------------------------------\n   #"
  },
  {
    "path": "lib/examples/hello_clock.rb",
    "chars": 2478,
    "preview": "class HelloClock < ArduinoSketch\n  \n# ----------------------------------------------------------------------------------"
  },
  {
    "path": "lib/examples/hello_eeprom.rb",
    "chars": 1423,
    "preview": "class HelloEeprom < ArduinoSketch\n  \n  output_pin 19, :as => :rtc, :device => :i2c_ds1307, :enable => :true\n  output_pin"
  },
  {
    "path": "lib/examples/hello_eeprom_lcdpa.rb",
    "chars": 2452,
    "preview": "class HelloEepromLcdpa < ArduinoSketch\n  # -----------------------------------------------------------------------\n  #  "
  },
  {
    "path": "lib/examples/hello_format_print.rb",
    "chars": 3269,
    "preview": "class HelloFormatPrint < ArduinoSketch\n\n  # ----------------------------------------------------------------------\n  #  "
  },
  {
    "path": "lib/examples/hello_lcd_charset.rb",
    "chars": 1709,
    "preview": "class HelloLcdCharset < ArduinoSketch\n\n  # -------------------------------------------------------------------------\n  #"
  },
  {
    "path": "lib/examples/hello_pa_lcd.rb",
    "chars": 1422,
    "preview": "class HelloPaLcd < ArduinoSketch\n\n\n# demonstrate 4 x 20 pa_lcd toggle between normal and Bignum mode\n# with @toggle exte"
  },
  {
    "path": "lib/examples/hello_servos.rb",
    "chars": 1229,
    "preview": "class HelloServos < ArduinoSketch\n  \n  output_pin 2, :as => :servo_1, :max => 2400, :min => 800\n  output_pin 3, :as => :"
  },
  {
    "path": "lib/examples/hello_spectra_sound.rb",
    "chars": 1227,
    "preview": "class HelloSpectraSound < ArduinoSketch\n\n  # demonstrate capability to use soft pot as traditional pot\n  # the last pot "
  },
  {
    "path": "lib/examples/hello_world.rb",
    "chars": 109,
    "preview": "class HelloWorld < ArduinoSketch\n  \n  output_pin 13, :as => :led\n\n  def loop\n    blink led, 100\n  end\n\nend\n\n\n"
  },
  {
    "path": "lib/examples/hello_xbee.rb",
    "chars": 171,
    "preview": "class HelloXbee < ArduinoSketch\n  \n  output_pin 13, :as => :led\n  \n  serial_begin\n  def loop\n    led.blink 200\n    seria"
  },
  {
    "path": "lib/examples/hysteresis_duel.rb",
    "chars": 938,
    "preview": "class HysteresisDuel < ArduinoSketch\n  \n  # purpose \n  # side by side demo of affect of hysteresis on two different sens"
  },
  {
    "path": "lib/examples/i2c_with_clock_chip.rb",
    "chars": 4722,
    "preview": "class I2cWithClockChip < ArduinoSketch\n  \n# ----------------------------------------------------------------------------"
  },
  {
    "path": "lib/examples/midi_beat_box.rb",
    "chars": 1725,
    "preview": "class MidiBeatBox < ArduinoSketch\n  \n  # midi synthesiser output on channel 2\n  # with speed controlled by spectra soft "
  },
  {
    "path": "lib/examples/midi_scales.rb",
    "chars": 2117,
    "preview": "class MidiScales < ArduinoSketch\n  \n# purpose\n# trigger midi output with buttons and\n# spectra soft pots\n#\n#\n\n\n  @curren"
  },
  {
    "path": "lib/examples/motor_knob.rb",
    "chars": 764,
    "preview": "class MotorKnob < ArduinoSketch\n\n# ----------------------------------------------------------\n#    MotorKnob adapted fro"
  },
  {
    "path": "lib/examples/servo_buttons.rb",
    "chars": 547,
    "preview": "class ServoButtons < ArduinoSketch\n  \n  # original syntax\n  input_pin 6, :as => :button_one, :latch => :off\n  # preferre"
  },
  {
    "path": "lib/examples/servo_calibrate_continuous.rb",
    "chars": 3337,
    "preview": "class ServoCalibrateContinuous < ArduinoSketch\n\n  # --------------------------------------------------------------------"
  },
  {
    "path": "lib/examples/servo_throttle.rb",
    "chars": 1146,
    "preview": "class ServoThrottle < ArduinoSketch\n\n     # updated 20080731 \n     # replaced external variables with instance style var"
  },
  {
    "path": "lib/examples/software_serial.rb",
    "chars": 193,
    "preview": "class SoftwareSerial < ArduinoSketch\n  output_pin 13, :as => :led\n  software_serial 6, 7, :as => :gps\n  serial_begin\n\n  "
  },
  {
    "path": "lib/examples/sparkfun_lcd.rb",
    "chars": 934,
    "preview": "class SparkfunLcd < ArduinoSketch\n\n\n  input_pin 6, :as => :button_one, :latch => :off\n  input_pin 7, :as => :button_two,"
  },
  {
    "path": "lib/examples/spectra_soft_pot.rb",
    "chars": 988,
    "preview": "class SpectraSoftPot < ArduinoSketch\n\n  # demonstrate capability to use soft pot as traditional pot\n  # the last pot rea"
  },
  {
    "path": "lib/examples/times_method.rb",
    "chars": 85,
    "preview": "class TimesMethod < ArduinoSketch\n\n  def loop\n    5.times { delay 200 }\n  end\n\n  \nend"
  },
  {
    "path": "lib/examples/toggle.rb",
    "chars": 134,
    "preview": "class Toggle < ArduinoSketch\n\n    output_pin 13, :as => :led\n\n       def loop\n         led.toggle\n         delay 300\n   "
  },
  {
    "path": "lib/examples/twitter.rb",
    "chars": 998,
    "preview": "class Twitter < ArduinoSketch\n  \n  #include <avr/io.h>\n  #include <string.h>\n\n\n\n  define \"TWEETLEN 141\"\n  define \"HOSTNA"
  },
  {
    "path": "lib/examples/two_wire.rb",
    "chars": 179,
    "preview": "class TwoWire < ArduinoSketch\n\n  # just a demo that two_wire loads\n\n  output_pin 19, :as => :wire, :device => :i2c, :ena"
  },
  {
    "path": "lib/libraries/Wire/utility/twi.c",
    "chars": 12432,
    "preview": "/*\n  twi.c - TWI/I2C library for Wiring & Arduino\n  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.\n\n  This l"
  },
  {
    "path": "lib/libraries/Wire/utility/twi.h",
    "chars": 1620,
    "preview": "/*\n  twi.h - TWI/I2C library for Wiring & Arduino\n  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.\n\n  This l"
  },
  {
    "path": "lib/plugins/bitwise_ops.rb",
    "chars": 1070,
    "preview": "class BitwiseOps < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and ca"
  },
  {
    "path": "lib/plugins/blink.rb",
    "chars": 599,
    "preview": "class Blink < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and calls \n"
  },
  {
    "path": "lib/plugins/blink_m.rb",
    "chars": 9134,
    "preview": "class BlinkM < ArduinoPlugin\n\n#\n#\n#  BlinkM_funcs.h -- Arduino library to control BlinkM\n#  --------------\n#\n#\n#  Note: "
  },
  {
    "path": "lib/plugins/debounce.rb",
    "chars": 4347,
    "preview": "class Debounce < ArduinoPlugin\n  \n\n  # RAD plugins are c methods, directives, external variables and assignments and cal"
  },
  {
    "path": "lib/plugins/debug_output_to_lcd.rb",
    "chars": 1776,
    "preview": "class DebugOutputToLcd < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments "
  },
  {
    "path": "lib/plugins/hysteresis.rb",
    "chars": 941,
    "preview": "class Hysteresis < ArduinoPlugin\n  \n# jdbarnhart\n# 20080728\n#\n#\n# purpose\n#\n# add hysteresis to analog readings, typical"
  },
  {
    "path": "lib/plugins/input_output_state.rb",
    "chars": 1681,
    "preview": "class InputOutputState < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments "
  },
  {
    "path": "lib/plugins/lcd_padding.rb",
    "chars": 1007,
    "preview": "class LCDPadding < ArduinoPlugin\n  \n# jdbarnhart\n# 20080729\n#\n#\n# purpose\n\n# simple integer padding for lcd display pad\n"
  },
  {
    "path": "lib/plugins/mem_test.rb",
    "chars": 1358,
    "preview": "class MemTest < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and calls"
  },
  {
    "path": "lib/plugins/midi.rb",
    "chars": 1686,
    "preview": "class Midi < ArduinoPlugin\n \n \n# reference \n  \n# To send MIDI, attach a MIDI out jack (female DIN-5) to Arduino.\n# DIN-5"
  },
  {
    "path": "lib/plugins/parallax_ping.rb",
    "chars": 1264,
    "preview": "class ParallaxPing < ArduinoPlugin\n\n  # RAD plugins are c methods, directives, external variables and assignments and ca"
  },
  {
    "path": "lib/plugins/servo_pulse.rb",
    "chars": 962,
    "preview": "class ServoPulse < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and ca"
  },
  {
    "path": "lib/plugins/servo_setup.rb",
    "chars": 2177,
    "preview": "class ServoSetup < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and ca"
  },
  {
    "path": "lib/plugins/smoother.rb",
    "chars": 1316,
    "preview": "class Smoother < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments and call"
  },
  {
    "path": "lib/plugins/spark_fun_serial_lcd.rb",
    "chars": 3091,
    "preview": "class SparkFunSerialLcd < ArduinoPlugin\n  \n  # RAD plugins are c methods, directives, external variables and assignments"
  },
  {
    "path": "lib/plugins/spectra_symbol.rb",
    "chars": 1536,
    "preview": "class SpectraSymbol < ArduinoPlugin\n  \n# jdbarnhart\n# 20080729\n#\n# crazy experiment in progress\n# purpose\n#\n# retain las"
  },
  {
    "path": "lib/plugins/twitter_connect.rb",
    "chars": 3665,
    "preview": "class TwitterConnect < ArduinoPlugin\n\n\n\n\nvoid get_tweet() {\n  // hack to pull \n}\n\nuint32_t parsenumber(char *str) {\n  ui"
  },
  {
    "path": "lib/rad/README.rdoc",
    "chars": 506,
    "preview": "=Welcome to RAD (Ruby Arduino Development) Quick Start Documentation\n\nArduinoSketch is the main access point for working"
  },
  {
    "path": "lib/rad/antiquated_todo.txt",
    "chars": 1888,
    "preview": "-framework for translation to C (wrapper for RubyToAnsiC)\n-framework for translation testing (want to test that each Rad"
  },
  {
    "path": "lib/rad/arduino_plugin.rb",
    "chars": 6907,
    "preview": "## RAD plugins -- the start\n\n## June 25, 2008\n## jd@jdbarnhart.com\n## \n\n\n# Disclaimer: This is only a first run at the n"
  },
  {
    "path": "lib/rad/arduino_sketch.rb",
    "chars": 23432,
    "preview": "# ArduinoSketch is the main access point for working with RAD. Sub-classes of ArduinoSketch have access to a wide array "
  },
  {
    "path": "lib/rad/darwin_installer.rb",
    "chars": 706,
    "preview": "class DarwinInstaller\n  def self.install!\n    puts \"Downloading arduino-0012 for Mac from Arduino.cc\"\n    File.open(\"/Ap"
  },
  {
    "path": "lib/rad/generators/makefile/makefile.erb",
    "chars": 7549,
    "preview": "# Arduino makefile\n#\n# This makefile allows you to build sketches from the command line\n# without the Arduino environmen"
  },
  {
    "path": "lib/rad/generators/makefile/makefile.rb",
    "chars": 1431,
    "preview": "require 'erb'\nrequire 'yaml'\n\nclass Makefile\n  class << self\n    \n    # build the sketch Makefile for the given template"
  },
  {
    "path": "lib/rad/hardware_library.rb",
    "chars": 25559,
    "preview": "class HardwareLibrary < ArduinoSketch\n  \n  def initialize\n    super\n  end\n  \n  # Treat a pair of digital I/O pins as a s"
  },
  {
    "path": "lib/rad/init.rb",
    "chars": 608,
    "preview": "RAD_ROOT = \"#{File.dirname(__FILE__)}/../..\" unless defined?(RAD_ROOT)\n\nunless defined?(PROJECT_DIR_NAME)\n  a = File.exp"
  },
  {
    "path": "lib/rad/linux_installer.rb",
    "chars": 4772,
    "preview": "class LinuxInstaller\n  \n  # this is the thing we actually run to make something happen\n  def self.install!\n    puts \"Wel"
  },
  {
    "path": "lib/rad/progressbar.rb",
    "chars": 5017,
    "preview": "#\n# Ruby/ProgressBar - a text progress bar library\n#\n# Copyright (C) 2001-2005 Satoru Takabayashi <satoru@namazu.org>\n# "
  },
  {
    "path": "lib/rad/rad_processor.rb",
    "chars": 3608,
    "preview": "require 'rubygems'\nrequire 'ruby_to_ansi_c'\n\nclass RADProcessor < RubyToAnsiC\n\n  def self.translator\n    unless defined?"
  },
  {
    "path": "lib/rad/rad_rewriter.rb",
    "chars": 3386,
    "preview": "require 'ruby_to_ansi_c'\n\nclass RADRewriter < Rewriter\n  \n  def process_iter(exp)\n    call = process exp.shift\n    var  "
  },
  {
    "path": "lib/rad/rad_type_checker.rb",
    "chars": 728,
    "preview": "require 'ruby_to_ansi_c'\n\nclass RADTypeChecker < TypeChecker\n  \n  def process_const(exp)\n    c = exp.shift\n    if c.to_s"
  },
  {
    "path": "lib/rad/sim/arduino_sketch.rb",
    "chars": 901,
    "preview": "ON = true\nOFF = !ON\nHIGH = ON\nLOW = !HIGH\n\nclass ArduinoSketch\n  attr_accessor :pins  \n   \n  def initialize\n    @pins = "
  },
  {
    "path": "lib/rad/sketch_compiler.rb",
    "chars": 1188,
    "preview": "# TODO:\n#   compilation\n#   gather pieces of code we need as strings\n#   translate non-loop methods\n#   do plugin stuff\n"
  },
  {
    "path": "lib/rad/tasks/build_and_make.rake",
    "chars": 7769,
    "preview": "require File.expand_path(File.dirname(__FILE__) + \"/../init.rb\")\nrequire 'ruby_to_ansi_c'\n\nC_VAR_TYPES = \"unsigned|int|l"
  },
  {
    "path": "lib/rad/tasks/rad.rb",
    "chars": 78,
    "preview": "require 'rake'\nDir[\"#{File.dirname(__FILE__)}/*.rake\"].each { |ext| load ext }"
  },
  {
    "path": "lib/rad/todo.txt",
    "chars": 346,
    "preview": "TODO:\n=====\n\t\nFuture:\n\t- complete library system: script/install library some_library\n\t- bin/rad:\n\t\t- setup and use a ~/"
  },
  {
    "path": "lib/rad/variable_processing.rb",
    "chars": 5261,
    "preview": "module ExternalVariableProcessing\n  # issues \n  # testing \n  # add checking for colon\n\n    \n    ## need to clean this up"
  },
  {
    "path": "lib/rad/version.rb",
    "chars": 143,
    "preview": "module Rad #:nodoc:\n  module VERSION #:nodoc:\n    MAJOR = 0\n    MINOR = 3\n    TINY  = 1\n\n    STRING = [MAJOR, MINOR, TIN"
  },
  {
    "path": "lib/rad.rb",
    "chars": 56,
    "preview": "module Rad\nend\n\nrequire 'rad/version'\nrequire 'rad/init'"
  },
  {
    "path": "rad.gemspec",
    "chars": 6383,
    "preview": "Gem::Specification.new do |s|\n  s.name = %q{rad}\n  s.version = \"0.3.1\"\n  s.date = %q{2008-08-18}\n  s.default_executable "
  },
  {
    "path": "scripts/txt2html",
    "chars": 1682,
    "preview": "#!/usr/bin/env ruby\n\nrequire 'rubygems'\nrequire 'redcloth'\nrequire 'syntax/convertors/html'\nrequire 'erb'\nrequire File.d"
  },
  {
    "path": "setup.rb",
    "chars": 36162,
    "preview": "#\n# setup.rb\n#\n# Copyright (c) 2000-2005 Minero Aoki\n#\n# This program is free software.\n# You can distribute/modify this"
  },
  {
    "path": "spec/examples/hello_world.rb",
    "chars": 197,
    "preview": "# Hardware: LED connected on pin 7\n\nclass HelloWorld < ArduinoSketch\n  output_pin 7, :as => :led\n  def loop\n    digitalW"
  },
  {
    "path": "spec/examples/serial_motor.rb",
    "chars": 309,
    "preview": "# Hardware: motor control circuit (i.e. TIP-120 control pin)\n#           connected at pin 7.\n#     Demo: http://www.yout"
  },
  {
    "path": "spec/models/arduino_sketch_spec.rb",
    "chars": 3815,
    "preview": "require File.dirname(__FILE__) + '/spec_helper.rb'\nrequire File.expand_path(File.dirname(__FILE__) + \"/../../lib/rad/ard"
  },
  {
    "path": "spec/models/sketch_compiler_spec.rb",
    "chars": 3040,
    "preview": "require File.dirname(__FILE__) + '/spec_helper.rb'\nrequire File.expand_path(File.dirname(__FILE__) + \"/../../lib/rad/ske"
  },
  {
    "path": "spec/models/spec_helper.rb",
    "chars": 34,
    "preview": "require 'rubygems'\nrequire 'spec'\n"
  },
  {
    "path": "spec/sim/hello_world_spec.rb",
    "chars": 1127,
    "preview": "require File.dirname(__FILE__) + './models/spec_helper.rb'\nrequire File.expand_path(File.dirname(__FILE__) + \"/../../lib"
  },
  {
    "path": "spec/spec.opts",
    "chars": 8,
    "preview": "--colour"
  },
  {
    "path": "test/hello_world_test/Makefile",
    "chars": 26093,
    "preview": "# Arduino makefile\n#\n# This makefile allows you to build sketches from the command line\n# without the Arduino environmen"
  },
  {
    "path": "test/hello_world_test/hello_world.cpp",
    "chars": 274,
    "preview": "#include <WProgram.h>\n\nvoid loop();\nvoid setup();\nint main();\n\nvoid setup() {\n\tpinMode(13, OUTPUT);\n}\n\nint main() {\n\tini"
  },
  {
    "path": "test/test_array_processing.rb",
    "chars": 4540,
    "preview": "$TESTING = true\n\n# need to tell it where we are\n# lets review these\n# neee to remove this constant from tests and pull i"
  },
  {
    "path": "test/test_plugin_loading.rb",
    "chars": 3868,
    "preview": "#!/usr/local/bin/ruby -w\n\n$TESTING = true\n\n# this is a test stub for now\n# lets review these\n# neee to remove this const"
  },
  {
    "path": "test/test_translation_post_processing.rb",
    "chars": 4711,
    "preview": "#!/usr/local/bin/ruby -w\n\n$TESTING = true\n\n# this is a test stub for now\n# lets review these\n# neee to remove this const"
  },
  {
    "path": "test/test_variable_processing.rb",
    "chars": 6259,
    "preview": "#!/usr/local/bin/ruby -w\n\n$TESTING = true\n\n# need to tell it where we are\n# lets review these\n# neee to remove this cons"
  },
  {
    "path": "website/examples/assembler_test.rb.html",
    "chars": 2769,
    "preview": "<html>\n  <head>\n    <title>assembler_test.rb.html</title\n    <style type=\"text/css\">\n\n\t.ruby .normal {}\n\t.ruby .comment "
  },
  {
    "path": "website/examples/gps_reader.rb.html",
    "chars": 1929,
    "preview": "<html>\n  <head>\n    <title>gps_reader.rb.html</title\n    <style type=\"text/css\">\n\n\t.ruby .normal {}\n\t.ruby .comment { co"
  },
  {
    "path": "website/examples/hello_world.rb.html",
    "chars": 1440,
    "preview": "<html>\n  <head>\n    <title>hello_world.rb.html</title\n    <style type=\"text/css\">\n\n\t.ruby .normal {}\n\t.ruby .comment { c"
  },
  {
    "path": "website/examples/serial_motor.rb.html",
    "chars": 1806,
    "preview": "<html>\n  <head>\n    <title>serial_motor.rb.html</title\n    <style type=\"text/css\">\n\n\t.ruby .normal {}\n\t.ruby .comment { "
  },
  {
    "path": "website/index.html",
    "chars": 9235,
    "preview": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmln"
  },
  {
    "path": "website/index.txt",
    "chars": 3660,
    "preview": "h1. RAD\n\nh1. &#x2192; 'Ruby Arduino Development'\n\nh2. What?\n\nRAD is a framework for programming the Arduino physcial com"
  },
  {
    "path": "website/javascripts/rounded_corners_lite.inc.js",
    "chars": 25082,
    "preview": "\n /****************************************************************\n  *                                                 "
  },
  {
    "path": "website/stylesheets/code.css",
    "chars": 570,
    "preview": ".ruby .normal {}\n.ruby .comment { color: #888; font-style: italic; }\n.ruby .keyword { color: #A00; font-weight: bold; }\n"
  },
  {
    "path": "website/stylesheets/screen.css",
    "chars": 2664,
    "preview": "body {\r\n  background-color: #E1D1F1;\r\n  font-family: \"Georgia\", sans-serif;\r\n  font-size: 16px;\r\n  line-height: 1.6em;\r\n"
  },
  {
    "path": "website/template.rhtml",
    "chars": 1494,
    "preview": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmln"
  }
]

About this extraction

This page contains the full source code of the atduskgreg/rad GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 114 files (384.7 KB), approximately 114.6k tokens, and a symbol index with 599 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!