Last active
October 6, 2016 10:43
-
-
Save LarsBergqvist/08465b5326caad7ee63ef4667cd62d36 to your computer and use it in GitHub Desktop.
Wrapper class for using the Arduino Firmata library in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.core.PApplet; | |
import processing.serial.*; | |
import cc.arduino.*; | |
public class ArduinoIntegration implements IArduinoIntegration { | |
// Change this so that it matches the usb device connected to the Arduino | |
String arduinoUSBDeviceName = "/dev/tty.usbmodem1421"; | |
Arduino arduino; | |
ArduinoIntegration(PApplet applet) { | |
try { | |
arduino = new Arduino(applet, arduinoUSBDeviceName , 57600); | |
} | |
catch(Exception e) { | |
println(e.getMessage()); | |
} | |
} | |
public float getVoltageFromPin(int pinNumber) { | |
if (arduino == null) | |
return 0; | |
float pinValue = arduino.analogRead(pinNumber); | |
float pinValueInVolts = map(pinValue,0,1024,0,5); | |
return pinValueInVolts; | |
} | |
public void setupAnalogPinAsInput(int pinNumber) { | |
if (arduino != null) { | |
arduino.pinMode(pinNumber, Arduino.INPUT); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment