mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Updating Firmata (to r62 of their repository).
Changes include (according to Paul Stoffregen): "1: Hardware abstraction layer to support Arduino Mega, Teensy and Sanguino. 2: Extended analog message, to facilitate using PWM and Servo above pin 15. 3: Capability queries (alpha), to allow automatic discovery of any board's features."
This commit is contained in:
@ -11,19 +11,19 @@ byte pin;
|
||||
int analogValue;
|
||||
int previousAnalogValues[TOTAL_ANALOG_PINS];
|
||||
|
||||
byte portStatus[TOTAL_PORTS];
|
||||
byte portStatus[TOTAL_PORTS]; // each bit: 1=pin is digital input, 0=other/ignore
|
||||
byte previousPINs[TOTAL_PORTS];
|
||||
|
||||
/* timer variables */
|
||||
unsigned long currentMillis; // store the current value from millis()
|
||||
unsigned long nextExecuteMillis; // for comparison with currentMillis
|
||||
unsigned long previousMillis; // for comparison with currentMillis
|
||||
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
|
||||
get long, random delays. So only read analogs every 20ms or so */
|
||||
int samplingInterval = 19; // how often to run the main loop (in ms)
|
||||
|
||||
void sendPort(byte portNumber, byte portValue)
|
||||
{
|
||||
portValue = portValue &~ portStatus[portNumber];
|
||||
portValue = portValue & portStatus[portNumber];
|
||||
if(previousPINs[portNumber] != portValue) {
|
||||
Firmata.sendDigitalPort(portNumber, portValue);
|
||||
previousPINs[portNumber] = portValue;
|
||||
@ -32,29 +32,37 @@ void sendPort(byte portNumber, byte portValue)
|
||||
|
||||
void setup()
|
||||
{
|
||||
byte i, port, status;
|
||||
|
||||
Firmata.setFirmwareVersion(0, 1);
|
||||
|
||||
for(pin = 0; pin < TOTAL_DIGITAL_PINS; pin++) {
|
||||
pinMode(pin, INPUT);
|
||||
for(pin = 0; pin < TOTAL_PINS; pin++) {
|
||||
if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
|
||||
}
|
||||
|
||||
portStatus[0] = B00000011; // ignore Tx/RX pins
|
||||
portStatus[1] = B11000000; // ignore 14/15 pins
|
||||
portStatus[2] = B00000000;
|
||||
for (port=0; port<TOTAL_PORTS; port++) {
|
||||
status = 0;
|
||||
for (i=0; i<8; i++) {
|
||||
if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
|
||||
}
|
||||
portStatus[port] = status;
|
||||
}
|
||||
|
||||
Firmata.begin(57600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
sendPort(0, PIND);
|
||||
sendPort(1, PINB);
|
||||
sendPort(2, PINC);
|
||||
byte i;
|
||||
|
||||
for (i=0; i<TOTAL_PORTS; i++) {
|
||||
sendPort(i, readPort(i));
|
||||
}
|
||||
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
|
||||
get long, random delays. So only read analogs every 20ms or so */
|
||||
currentMillis = millis();
|
||||
if(currentMillis > nextExecuteMillis) {
|
||||
nextExecuteMillis = currentMillis + samplingInterval;
|
||||
if(currentMillis - previousMillis > samplingInterval) {
|
||||
previousMillis += samplingInterval;
|
||||
while(Firmata.available()) {
|
||||
Firmata.processInput();
|
||||
}
|
||||
|
Reference in New Issue
Block a user