Add example for Engduino boards // Resolve #76

This commit is contained in:
Valeriy Koval
2015-02-23 14:25:11 +02:00
parent d1ca17c406
commit 6e0ebdbc94
3 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,21 @@
How to buid PlatformIO based project
====================================
1. `Install PlatformIO <http://docs.platformio.org/en/latest/installation.html>`_
2. Download `source code with examples <https://github.com/ivankravets/platformio/archive/develop.zip>`_
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

View File

@ -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

View File

@ -0,0 +1,60 @@
#include <EngduinoLEDs.h>
#include <EngduinoAccelerometer.h>
#include <Wire.h>
// 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);
}