Last active
November 27, 2016 00:01
-
-
Save soundanalogous/7e7643cd8cf00a5f90de615f5d52b9ec to your computer and use it in GitHub Desktop.
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
#include <ConfigurableFirmata.h> | |
#include <DigitalInputFirmata.h> | |
DigitalInputFirmata digitalInput; | |
#include <DigitalOutputFirmata.h> | |
DigitalOutputFirmata digitalOutput; | |
#include <AnalogInputFirmata.h> | |
AnalogInputFirmata analogInput; | |
#include <AnalogOutputFirmata.h> | |
AnalogOutputFirmata analogOutput; | |
#include <Wire.h> | |
#include <I2CFirmata.h> | |
I2CFirmata i2c; | |
#include <OneWireFirmata.h> | |
OneWireFirmata oneWire; | |
#include <FirmataScheduler.h> | |
FirmataScheduler scheduler; | |
#include <FirmataExt.h> | |
FirmataExt firmataExt; | |
#include <AnalogWrite.h> | |
#include <FirmataReporting.h> | |
FirmataReporting reporting; | |
void systemResetCallback() | |
{ | |
for (byte i = 0; i < TOTAL_PINS; i++) { | |
if (IS_PIN_ANALOG(i)) { | |
Firmata.setPinMode(i, ANALOG); | |
} else if (IS_PIN_DIGITAL(i)) { | |
Firmata.setPinMode(i, OUTPUT); | |
} | |
} | |
firmataExt.reset(); | |
} | |
void initTransport() | |
{ | |
// Uncomment to save a couple of seconds by disabling the startup blink sequence. | |
// Firmata.disableBlinkVersion(); | |
Firmata.begin(57600); | |
} | |
void initFirmata() | |
{ | |
Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); | |
firmataExt.addFeature(digitalInput); | |
firmataExt.addFeature(digitalOutput); | |
firmataExt.addFeature(analogInput); | |
firmataExt.addFeature(analogOutput); | |
firmataExt.addFeature(i2c); | |
firmataExt.addFeature(oneWire); | |
firmataExt.addFeature(scheduler); | |
firmataExt.addFeature(reporting); | |
Firmata.attach(SYSTEM_RESET, systemResetCallback); | |
} | |
void setup() | |
{ | |
initFirmata(); | |
initTransport(); | |
systemResetCallback(); | |
// set sampling interval to 1000ms | |
reporting.setSamplingInterval(1000); | |
} | |
void loop() | |
{ | |
digitalInput.report(); | |
while(Firmata.available()) { | |
Firmata.processInput(); | |
if (!Firmata.isParsingMessage()) { | |
goto runtasks; | |
} | |
} | |
if (!Firmata.isParsingMessage()) { | |
runtasks: scheduler.runTasks(); | |
} | |
if (reporting.elapsed()) { | |
analogInput.report(); | |
i2c.report(); | |
Firmata.sendString("reporting..."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment