Testing Pitchfork's accelerometer control with Neopixels

Wrote some simple code tonight to test accelerometer control from the iPhone on a Neopixel ring.

Very sweet! Would be even nicer to “roll” a lit pixel around the ring vs segments though :slight_smile:

:slight_smile: I’m getting there. My lame coding skills have to take it one step at a time. The other issue getting the http requests in and out nicely. I don’t want to constantly slam requests at the server. I think I had that set at .5 reads.

Do you have any suggestions about how fast is too fast to try to send requests to the agent?

It’s a little hard right now, we need to implement the streaming inbound requests really (you can do them outbound from the agent but not inbound)

I wrote code to turn on each individual pixel with the accelerometer, but its totally crashing the device at the moment… just a bunch of nested if statements… not sure how to do it more efficiently.

If you turn the accelerometer X/Y into an angle, then it’d just be turning on pixel (degrees / 22.5)?

How is this?

agent.on("accelerometer", function(data) { //Convert x,y to degrees local d = math.atan2(data.XAxis, data.YAxis) * 180/PI; //Convert to 360 degrees if (d < 0) { d = 360 + d; } //Get the pixel for that range of degrees (360/16 neopixels) local pixel = (d/22.5).tointeger(); //Flip the rotation of the Neopixels pixel = 15 - pixel; //Write the pixels pixelStrip.clearFrame(); for (local p = 0; p < NUMPIXELS; p++) { if (p == pixel) { pixelStrip.writePixel(p, red, green, blue); } else { pixelStrip.writePixel(p, 0, 0, 0); } } pixelStrip.writeFrame(); });

“This video is private”…

Ooops… fixed.

Adding GPS information now. I’d like to see someone Imp a quadcopter and have it follow them around. It will be interesting to see if I can get the Neopixel ring to point in my direction as I walk around it. MIght have to do some heavy averaging with the +/- 5.00m accuracy.