Last week, the Avengers: Age of Ultron premiered in the US. We were pretty excited about it, so we decided to honor our favorite heroic maker, Tony Stark.
(Like a true DIY-er, Tony builds things with what he has, in a cave, from a box of scraps.)
In honor of Iron Man and his Avengers buddies, we built the Repulsor and Arc Reactor – or as we like to call it, the Spark Reactor.
Want to build one of your own? We’ll break down how to build and program the Repulsor, the servo, and the Spark Reactor.
The Repulsor
The Repulsor is made of a Core and Internet Button. This project will also be easy to replicate with the new Photon. You can solder a JST connector onto the back of the Button if you don’t want to deal with wires.
The Repulsor uses the Internet Button’s built-in accelerometer to determine what position your hand is in. It sets its colors and sounds based on the button’s orientation. Therefore, it will only “charge” when your hand is holding it, USB-port down, at about a 30 degree angle from the ground. It will only be “fully charged” when your hand is at a 90 degree angle from the ground. It will only “discharge” when fully charged and thrust forward.
Upon discharge, the Repulsor publishes a fire_repulsor
event to the cloud. Basically, it notifies the cloud that something happened, and any devices or websites listening in for that event get the word. You can see the code for the Repulsor below:
The Servo
While I was building the Repulsor, my good buddy– Office Manager James Jarvey– was building simple servo that would listen in for the fire_repulsor
event.
James wired the servo up like this…
…And loaded the following code to his own Spark Core:
The servo is subscribed to the cloud, listening specifically for the fire_repulsor
event. Note that even though the Core was claimed to James’s account, it can still listen for a public event published from someone else’s Core, in this case, mine. We could also have made the event private and loaded this code to a core on my account instead. If you want to do that, then uncomment and comment the indicated code in each app to change the privacy of subscribe and publish.
When I fire the repulsor, the fire_repulsor
event is published. The servo gets wind of that event and triggers the “ function, which in turn tells the servo to spasm.
The Spark Reactor
We also made what we’re calling the Spark Reactor, a chest piece to wear when you fire your repulsor.
The Spark Reactor breathes blue-tinted light, and it flashes yellow when the repulsor is fired.
The basic principle behind the Spark Reactor is similar to the servo– it is subscribed to the cloud for the fire_repulsor
event. When it hears that that event is published, it triggers the lightResponse
function, which changes the state of the Spark Reactor so that it flashes yellow.
Because math is awesome, this program uses a sin function to calculate the color and brightness of the LED as it breathes, and a linear function for the flash response. This means you can change the parameters a bit if you need the LED to be faster, slower, or a different color.
Including the Spark Button Library
When you create these apps, don’t forget to include the Spark Button library.
After you paste the code into your build environment, save the app and go to the library drawer on the botton left. Select the Spark Button library.
Then, select “Include In App.”
Select your app.
An #include
statement will get added to your app:
Feel free to delete this if it is already there; the important thing is that the library is now a part of your app.
In Conclusion…
Put it all together, and you’re ready to defeat Ultron and reclaim your bananas. Guaranteed defeat of action-figure-sized Ultron only. Have fun!