Hola ,
Sigo leyendo mucho aqui, y de vez en cuando pregunto para resolver las dudas planteadas, y aunque ya he preguntado en el hilo "Memorizar posición de los servos al encender arduino." al encontrar un programa muy similar en este hilo, pero para 8 componentes y usando las señales analogicas A...A5, como salida, entiendo la utilizacion de las 8 salidas.
Pero en este caso tambien uso Arduino para mover desvios con servos, y utilizo el UNO R3, pero cuando veo las conexiones "attach" para las bobinas, y veo salidas por los pin 22, 23, 24,......pues me pierdo pues solo veo que desde la 2 que usa las entradas DCC, tengo la posibilidad de utilizar hasta la 13 , teniendo solamente 10 posibilidades, aunque utilizarse las salidas analogicas me daria para 16 salidas pero como hay que usar dos por cada bobina pues se queda en 8 y no alcanzo a ver mas, adjunto el codigo para que se vea mas claro lo que intento solicitar:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Arduino DCC Solenoid Switch Decoder.
// Author: Ruud Boer - January 2015
// This sketch turns an Arduino into a DCC decoder to drive max 8 dual coil solenoid switches.
// The DCC signal is optically separated and fed to pin 2 (=Interrupt 0). Schematics: http://www.mynabay.com
// Many thanks to http://www.mynabay.com for publishing their DCC monitor and -decoder code.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// IMPORTANT: GOTO lines 17 and 40 to configure some data!
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <DCC_Decoder.h>
#define kDCC_INTERRUPT 0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FILL IN
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const byte maxaccessories=10; //The number of switches you want to control with this Arduino
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct
{
int address; // Address to respond to
byte output; // State of accessory: 1=on, 0=off (for internal use only)
int outputPin; // Arduino output pin
int outputPin2; // Arduino output pin2, used for solenoid junctions
byte highlow; // State of outputpin: 1=HIGH, 0=LOW
byte highlow2; // State of outputpin2: 1=HIGH, 0=LOW
boolean finished; // Memory location that says the oneshot is finished
boolean finished2; // Memory location that says the second oneshot (for solenoid) is finished
int durationMilli; // ms flash time
unsigned long onMilli; // for internal use
unsigned long offMilli; // for internal use
}
DCCAccessoryAddress;
DCCAccessoryAddress accessory[maxaccessories];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialization: COPY - PASTE the structure as many times as you have switches and fill in the values you want.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void ConfigureDecoderFunctions() // The amount of accessories must be same as in line 26 above!
{
accessory[0].address = 1;
accessory[0].durationMilli = 250;
accessory[0].outputPin = 3;
accessory[0].outputPin2 = 4;
accessory[0].highlow = 0; // Do not change this value
accessory[0].highlow2 = 0; // Do not change this value
accessory[0].finished = false; // Do not change this value
accessory[0].finished2 = true; // Do not change this value
accessory[0].output = 0; // Do not change this value
accessory[1].address = 2;
accessory[1].durationMilli = 250;
accessory[1].outputPin = 5;
accessory[1].outputPin2 = 6;
accessory[1].highlow = 0; // Do not change this value
accessory[1].highlow2 = 0; // Do not change this value
accessory[1].finished = false; // Do not change this value
accessory[1].finished2 = true; // Do not change this value
accessory[1].output = 0; // Do not change this value
accessory[2].address = 3;
accessory[2].durationMilli = 250;
accessory[2].outputPin = 7;
accessory[2].outputPin2 = 8;
accessory[2].highlow = 0; // Do not change this value
accessory[2].highlow2 = 0; // Do not change this value
accessory[2].finished = false; // Do not change this value
accessory[2].finished2 = true; // Do not change this value
accessory[2].output = 0; // Do not change this value
accessory[3].address = 4;
accessory[3].durationMilli = 250;
accessory[3].outputPin = 9;
accessory[3].outputPin2 = 10;
accessory[3].highlow = 0; // Do not change this value
accessory[3].highlow2 = 0; // Do not change this value
accessory[3].finished = false; // Do not change this value
accessory[3].finished2 = true; // Do not change this value
accessory[3].output = 0; // Do not change this value
accessory[4].address = 5;
accessory[4].durationMilli = 250;
accessory[4].outputPin = 11;
accessory[4].outputPin2 = 12;
accessory[4].highlow = 0; // Do not change this value
accessory[4].highlow2 = 0; // Do not change this value
accessory[4].finished = false; // Do not change this value
accessory[4].finished2 = true; // Do not change this value
accessory[4].output = 0; // Do not change this value
accessory[5].address = 6;
accessory[5].durationMilli = 250;
accessory[5].outputPin = 13;
accessory[5].outputPin2 = 14;
accessory[5].highlow = 0; // Do not change this value
accessory[5].highlow2 = 0; // Do not change this value
accessory[5].finished = false; // Do not change this value
accessory[5].finished2 = true; // Do not change this value
accessory[5].output = 0; // Do not change this value
accessory[6].address = 7;
accessory[6].durationMilli = 250;
accessory[6].outputPin = 15;
accessory[6].outputPin2 = 16;
accessory[6].highlow = 0; // Do not change this value
accessory[6].highlow2 = 0; // Do not change this value
accessory[6].finished = false; // Do not change this value
accessory[6].finished2 = true; // Do not change this value
accessory[6].output = 0; // Do not change this value
accessory[7].address = 8;
accessory[7].durationMilli = 250;
accessory[7].outputPin = 17;
accessory[7].outputPin2 = 18;
accessory[7].highlow = 0; // Do not change this value
accessory[7].highlow2 = 0; // Do not change this value
accessory[7].finished = false; // Do not change this value
accessory[7].finished2 = true; // Do not change this value
accessory[7].output = 0; // Do not change this value
accessory[8].address = 9;
accessory[8].durationMilli = 250;
accessory[8].outputPin = 19;
accessory[8].outputPin2 = 20;
accessory[8].highlow = 0; // Do not change this value
accessory[8].highlow2 = 0; // Do not change this value
accessory[8].finished = false; // Do not change this value
accessory[8].finished2 = true; // Do not change this value
accessory[8].output = 0; // Do not change this value
accessory[9].address = 10;
accessory[9].durationMilli = 250;
accessory[9].outputPin = 21;
accessory[9].outputPin2 = 22;
accessory[9].highlow = 0; // Do not change this value
accessory[9].highlow2 = 0; // Do not change this value
accessory[9].finished = false; // Do not change this value
accessory[9].finished2 = true; // Do not change this value
accessory[9].output = 0; // Do not change this value
// Setup output pins
for(int i=0; i<maxaccessories; i++)
{
if( accessory[i].outputPin )
{
pinMode( accessory[i].outputPin, OUTPUT );
digitalWrite( accessory[i].outputPin, HIGH);
}
if( accessory[i].outputPin2 )
{
pinMode( accessory[i].outputPin2, OUTPUT );
digitalWrite( accessory[i].outputPin2, HIGH);
}
}
} // END ConfigureDecoderFunctions
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DCC packet handler
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data)
{
// Convert NMRA packet address format to human address
address -= 1;
address *= 4;
address += 1;
address += (data & 0x06) >> 1;
boolean enable = (data & 0x01) ? 1 : 0;
for(int i=0; i<maxaccessories; i++)
{
if( address == accessory[i].address )
{
if( enable ) accessory[i].output = 1;
else accessory[i].output = 0;
}
}
} // END BasicAccDecoderPacket_Handler
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Setup (run once)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup()
{
DCC.SetBasicAccessoryDecoderPacketHandler(BasicAccDecoderPacket_Handler, true);
ConfigureDecoderFunctions();
DCC.SetupDecoder( 0x00, 0x00, kDCC_INTERRUPT );
pinMode(2,INPUT_PULLUP); //Interrupt 0 with internal pull up resistor (can get rid of external 10k)
pinMode(13,OUTPUT);
digitalWrite(13,HIGH); //turn off Arduino led at startup
for (int n=0; n<maxaccessories; n++) accessory[n].output = 0; //all servo's to min angle and functions to 0
} //END setup
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Main loop (run continuous)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop()
{
static int addr = 0;
DCC.loop(); // Loop DCC library
if( ++addr >= maxaccessories ) addr = 0; // Bump to next address to test
if (accessory[addr].output == 1)
{
if (!accessory[addr].highlow && !accessory[addr].finished)
{
accessory[addr].highlow = 1;
accessory[addr].offMilli = millis() + accessory[addr].durationMilli;
}
if (accessory[addr].highlow && millis() > accessory[addr].offMilli)
{
accessory[addr].highlow = 0;
accessory[addr].finished = true;
}
accessory[addr].finished2 = false;
}
else // output==0
{
accessory[addr].highlow=0;
accessory[addr].finished = false;
if (!accessory[addr].highlow2 && !accessory[addr].finished2)
{
accessory[addr].highlow2 = 1;
accessory[addr].offMilli = millis() + accessory[addr].durationMilli;
}
if (accessory[addr].highlow2 && millis() > accessory[addr].offMilli)
{
accessory[addr].highlow2 = 0;
accessory[addr].finished2 = true;
}
}
if (accessory[addr].highlow) digitalWrite( accessory[addr].outputPin, LOW);
else digitalWrite( accessory[addr].outputPin, HIGH);
if (accessory[addr].highlow2) digitalWrite( accessory[addr].outputPin2,LOW);
else digitalWrite( accessory[addr].outputPin2, HIGH);
} //END loop
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Como se puede observar como mucho para un Arduino UNO R3, solamente se pueden controlar 8 desvios
Alguien podria indicarme si se utiliza un" modulo Controlador de servos PCA9685", pues no veo en la declaracion del principio del programa la llamada a las librerias.
Tambien me gustaria conocer el esquema de trabajao con su cableado desde el Arduino.
Y conocer si se utiliza otro tipo de tablero que no sea el UNO R3.
Gracias por la atencion prestada.
Saludos cordiales.
Lukas