Skip to content

Commit

Permalink
Minor change, README update
Browse files Browse the repository at this point in the history
  • Loading branch information
pAIgn10 committed Mar 24, 2014
1 parent 0a49a6e commit 4a62daf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
35 changes: 34 additions & 1 deletion README.md
@@ -1,4 +1,37 @@
ArduinoPixel
============

An Android app that communicates with an Arduino Web server to control a NeoPixel LED strip.
This project consists of two pieces. The first piece is an **Arduino sketch** that implements a **Web Server** and offers an **API** for controlling a [NeoPixel LED Strip](http://www.adafruit.com/products/1138). The second piece is an **Android app**, `ArduinoPixel`, that connects to the **Arduino Web Server** and sends **commands** to control the **color** and the **on/off state** of the **LED strip**.

<br>
![promo](http://i859.photobucket.com/albums/ab154/lampnick67/promo__zpsbbabfe87.png)
<br><br>

The **Arduino sketch** is also available at [codebender](https://codebender.cc/sketch:31742). You can **clone** the project, **update** the controller and network parameters, and **upload** it straight to your **Arduino Ethernet**, or any other Arduino compatible board w/ an Ethernet Shield.

The **Android application** is available on [Google Play](https://play.google.com/store/apps/details?id=ln.paign10.arduinopixel). **Install** the app to your phone or tablet, **configure** the network parameters you set earlier in the Arduino sketch, and you are **ready** to go. You can watch a demo on [YouTube](http://www.youtube.com/watch?v=AuqOQ0Pe_c0).

API
---

The server accepts the following HTTP requests:
* A `GET` request to `/`. It responds with a **Hello from Arduino Server** message.
* A `GET` request to `/strip/status/`. It responds with **ON** or **OFF** for the on/off state of the strip.
* A `GET` request to `/strip/color/`. It responds with a **JSON representation** of the strip's **color**, e.g. `{"r":92,"g":34,"b":127}`.
* A `PUT` request to `/strip/status/on`. It **turns** the strip **on**.
* A `PUT` request to `/strip/status/off`. It **turns** the strip **off**.
* A `PUT` request to `/strip/color/`. It **changes** the strip's **color**. The **data** are delivered as a **JSON object**, e.g. `{"r":48,"g":254,"b":176}`.


Testing
-------

The **Android app** was tested on a tablet with Android v`4.1.1`.


Attribution
-----------

The **Android app** makes use of **Piotr Adamus'** [ColorPicker](https://github.com/chiralcode/Android-Color-Picker) view.

**Thank you Piotr**... with your **beautiful** work, you gave me the motivation I needed to attempt this project.
Expand Up @@ -138,19 +138,27 @@ public void onCheckedChanged(CompoundButton buttonView,
});

mToast = Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT);

executor = Executors.newScheduledThreadPool(1);
}

@Override
protected void onResume() {
online = false;
if (isNetworkAvailable())
new HttpTask(Method.GET, URI_STATUS).execute();
// if (isNetworkAvailable())
new HttpTask(Method.GET, URI_STATUS).execute();

super.onResume();
}

@Override
protected void onPause() {
if (mCheckHost != null)
cancelExecutor();

super.onPause();
}

private class HttpTask extends AsyncTask<Integer, Void, String> {
private AndroidHttpClient mClient = AndroidHttpClient.newInstance("");
private Method reqMethod; // HTTP request method
Expand Down Expand Up @@ -280,7 +288,7 @@ private void parseJsonData(String result) {
String[] optNames = { "r", "g", "b" };
for (int i = 0; i < 3; ++i)
mColor[i] = responseObject.optInt(optNames[i]);

mColorPicker.setColor(Color.rgb(mColor[0], mColor[1], mColor[2]));
mColorPicker.postInvalidate();

Expand All @@ -297,21 +305,22 @@ public static synchronized boolean isOnline() {

// Updates the power state of the LED strip
private void updatePowerState(boolean state) {
mState = state;

if (!isNetworkAvailable()) {
mToast.setText("Network Unavailable");
mToast.show();
online = false;
if (mCheckHost == null)
startExecutor();
return;
}

if (online) {
if (state) {
mState = true;
if (state)
new HttpTask(Method.PUT, URI_STATUS_ON).execute();
} else {
mState = false;
else
new HttpTask(Method.PUT, URI_STATUS_OFF).execute();
}
}
}

Expand Down

0 comments on commit 4a62daf

Please sign in to comment.