Quantcast
Channel: vertical challenge » android | vertical challenge
Viewing all articles
Browse latest Browse all 12

yun REST lighting

$
0
0

long-leds


progress on the rgb leds continues, here is the code for a useful android testing tool, with a very brutal looking UI.. awful. sliders for the red, green, blue light levels, few buttons for presets and scrolling debug messaging. the only noteworthy thing is defining the range of the sliders to suit the pwm levels on the arduino end.. so, [0 - 255] values for each colour. I was trying to adjust these max values to actually set the max levels of light to get the brightest, whitest whites. the blue led is very much brighter so simply maxing them out doesn’t give you a proper white colour using the dealextreme ones I found. the circuit for these led’s, some code hints that got me startert cand be found on the server box blog.


...
android:id="@+id/redSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:max="255"
...

simply load the bridge REST example code into the yun.

getting updates on a timer is easy, just remember the create a new thread for everything. using the REST url for retrieving all the arduino’s pin states and variables is best done all at once and then doing a quick parse. just chop out the matching values for each pin on the arduino.


...
String url = ARDUINO_IP_ADDRESS+"/data/get/";
String body = new DefaultHttpClient().execute(new HttpGet(url), 
    new BasicResponseHandler());
	
// sample reply is as follows 					
// {"value":{"D6":"0","D5":"0","D3":"59"},"response":"get"}

String red = body.substring(body.indexOf("D" + RED_PIN + "\":\"")+5); 
String redrest = red.substring(0, red.indexOf("\""));
int rednow = Integer.parseInt(redrest);
...	
updateText("r[" + rednow + "]  g[" + greennow + "  b[" + bluenow +"]");	

// now be sure the seek bar is up to date, another 
// device might have changed the values 			
seekRed.setProgress(rednow);
...


I have put the android project files on my server if anyone cares to expand on this project. There is exactly zero effort put into the gui at this point, because I’m awful at user interfaces and ultimately this will all be run as scripts by the home automation server anyway. the rest of this system include a jetty server, servlets, batteries and wifi controlled robots. more soon.


To test from my laptop I often use the curl command instead of a web browser, it’s just faster to scroll through the command history on the command line.


macbook:~ brad$ curl 192.168.1.10/data/get 
{"value":{"D6":"94","D5":"106","D3":"69"},"response":"get"}



In a browser you’ll see something like the following:





Viewing all articles
Browse latest Browse all 12

Latest Images

Trending Articles





Latest Images