From 6e0ebdbc94abf79b276489c9db15ee5f56944ae8 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Mon, 23 Feb 2015 14:25:11 +0200 Subject: [PATCH] Add example for Engduino boards // Resolve #76 --- .../arduino-engduino-library/README.rst | 21 +++++++ .../arduino-engduino-library/platformio.ini | 23 +++++++ .../arduino-engduino-library/src/src.pde | 60 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 examples/atmelavr-and-arduino/arduino-engduino-library/README.rst create mode 100644 examples/atmelavr-and-arduino/arduino-engduino-library/platformio.ini create mode 100644 examples/atmelavr-and-arduino/arduino-engduino-library/src/src.pde diff --git a/examples/atmelavr-and-arduino/arduino-engduino-library/README.rst b/examples/atmelavr-and-arduino/arduino-engduino-library/README.rst new file mode 100644 index 00000000..832502f5 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-engduino-library/README.rst @@ -0,0 +1,21 @@ +How to buid PlatformIO based project +==================================== + +1. `Install PlatformIO `_ +2. Download `source code with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platformio-develop/examples/atmelavr-and-arduino/ardiono-engduino-library + + # Process example project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/atmelavr-and-arduino/arduino-engduino-library/platformio.ini b/examples/atmelavr-and-arduino/arduino-engduino-library/platformio.ini new file mode 100644 index 00000000..8eaa3092 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-engduino-library/platformio.ini @@ -0,0 +1,23 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:engduinov3] +platform = atmelavr +framework = arduino +board = engduinov3 \ No newline at end of file diff --git a/examples/atmelavr-and-arduino/arduino-engduino-library/src/src.pde b/examples/atmelavr-and-arduino/arduino-engduino-library/src/src.pde new file mode 100644 index 00000000..8e9eab51 --- /dev/null +++ b/examples/atmelavr-and-arduino/arduino-engduino-library/src/src.pde @@ -0,0 +1,60 @@ +#include +#include +#include + +// Accelerometer demo - level +// +// Show a red LED on one side if we're low on that side +// show nothing if we're high, and show green on both sides +// if it's level(ish) +// +// We delay between readings because it's a bit flashy +// otherwise - too hard to hold steady +// + +void setup() +{ + EngduinoLEDs.begin(); + EngduinoAccelerometer.begin(); +} + +void loop() +{ float xyz[3]; + + // Read the acceleration + // + EngduinoAccelerometer.xyz(xyz); + + // And light the appropriate LEDs depending on whether we're level + // or not. The LEDs chosen are on opposite sides of the board. + // + if ((xyz[0] > 0 && xyz[0] < 0.02) || (xyz[0] < 0 && xyz[0] > -0.02)) { + EngduinoLEDs.setLED(12, GREEN); + EngduinoLEDs.setLED( 4, GREEN); + } + else if (xyz[0] > 0.02) { + EngduinoLEDs.setLED(12, RED); + EngduinoLEDs.setLED( 4, OFF); + } + else { + EngduinoLEDs.setLED(12, OFF); + EngduinoLEDs.setLED( 4, RED); + } + + if ((xyz[1] > 0 && xyz[1] < 0.02) || (xyz[1] < 0 && xyz[1] > -0.02)) { + EngduinoLEDs.setLED( 9, GREEN); + EngduinoLEDs.setLED(15, GREEN); + } + else if (xyz[1] > 0.02) { + EngduinoLEDs.setLED( 9, RED); + EngduinoLEDs.setLED(15, OFF); + } + else { + EngduinoLEDs.setLED( 9, OFF); + EngduinoLEDs.setLED(15, RED); + } + + // Wait 50ms, then loop + // + delay(50); +} \ No newline at end of file