...
Code Block | ||||
---|---|---|---|---|
| ||||
import br.com.criativasoft.opendevice.connection.ConnectionListener; import br.com.criativasoft.opendevice.connection.ConnectionStatus; import br.com.criativasoft.opendevice.connection.DeviceConnection; import br.com.criativasoft.opendevice.connection.message.Message; import br.com.criativasoft.opendevice.core.command.DeviceCommand; import br.com.criativasoft.opendevice.core.connection.Connections; public class BlinkCommandDemo implements ConnectionListener { public BlinkCommandDemo() throws Exception { DeviceConnection conn = Connections.out.usb(); conn.addListener(this); conn.connect(); long delay = 500; while(conn.isConnected()) { conn.send(DeviceCommand.ON(1)); // '1' is Device ID not pin ! Thread.sleep(delay); conn.send(DeviceCommand.OFF(1)); Thread.sleep(delay); } System.out.println("TERMINATED !"); } public static void main(String[] args) throws Exception { new BlinkCommandDemo(); } // ------------------------------------------------------------ // ------------- ConnectionListener Impl -------------------------- public void onMessageReceived(Message message, DeviceConnection connection) { String type = message.getClass().getSimpleName(); System.out.println("onMessageReceived("+type+"): "+ message); } public void connectionStateChanged(DeviceConnection connection, ConnectionStatus status) { System.out.println("connectionStateChanged : " + status); } } |
Now that you have control of the gates of Arduino, you can control various devices such as lamps, fans, coffeemakers, robots, etc. ..
To control this type of device you will need a relay, which is a device capable of controlling high voltages.
Examples:
These modules are ready, but it's quite easy to build your own, if you have some knowledge in electronics.
Reference: http://openenergymonitor.org/emon/buildingblocks/mains-ac-relay-module
Tutorial: http://www.instructables.com/id/Connecting-a-12V-Relay-to-Arduino/
Troubleshooting
If you have a problem, check this guide: Troubleshooting