Add files via upload

This commit is contained in:
Geoff Bunza
2018-07-05 15:18:48 -07:00
committed by GitHub
parent f171dd3894
commit c2de60b8cb
20 changed files with 2940 additions and 269 deletions

View File

@@ -1,5 +1,9 @@
// Production 17 Function DCC Decoder
// Version 5.4 Geoff Bunza 2014,2015,2016
// Production 17 Switch Acessory DCC Decoder AccDec_17LED_1Ftn.ino
// Version 6.0 Geoff Bunza 2014,2015,2016,2017,2018
// Now works with both short and long DCC Addesses for CV Control Default 24 (LSB CV 121 ; MSB CV 122)
// ACCESSORY DECODER DEFAULT ADDRESS IS 40 (MAX 40-56 SWITCHES)
// ACCESSRY DECODER ADDRESS CAN NOW BE SET ABOVE 255
// BE CAREFUL! DIFFERENT DCC BASE STATIONS ALLOW DIFFERING MAX ADDRESSES
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
@@ -9,7 +13,7 @@
int tim_delay = 500;
#define numleds 17
byte ledpins [] = {0,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
byte ledpins [] = {3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
const int FunctionPin0 = 3;
const int FunctionPin1 = 4;
@@ -31,9 +35,14 @@ const int FunctionPin16 = 19; //A5
NmraDcc Dcc ;
DCC_MSG Packet ;
#define This_Decoder_Address 40 //ACCESSORY DECODER ADDRESS
//Start of SWITCHES RANGE
uint8_t CV_DECODER_MASTER_RESET = 120;
#define SET_CV_Address 24 // THIS ADDRESS IS FOR SETTING CV'S Like a Loco
#define Accessory_Address 40 // THIS ADDRESS IS THE START OF THE SWITCHES RANGE
// WHICH WILL EXTEND FOR 16 MORE SWITCH ADDRESSES
// THIS CAN START ABOVE ADDRESS 256
uint8_t CV_DECODER_MASTER_RESET = 120; // THIS IS THE CV ADDRESS OF THE FULL RESET
#define CV_To_Store_SET_CV_Address 121
#define CV_Accessory_Address CV_ACCESSORY_DECODER_ADDRESS_LSB
struct CVPair
{
uint16_t CV;
@@ -41,11 +50,21 @@ struct CVPair
};
CVPair FactoryDefaultCVs [] =
{
{CV_ACCESSORY_DECODER_ADDRESS_LSB, This_Decoder_Address},
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
// These two CVs define the Long Accessory Address
{CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address&0xFF},
{CV_ACCESSORY_DECODER_ADDRESS_MSB, (Accessory_Address>>8)&0x07},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
// Speed Steps don't matter for this decoder
// ONLY uncomment 1 CV_29_CONFIG line below as approprate DEFAULT IS SHORT ADDRESS
// {CV_29_CONFIG, 0}, // Short Address 14 Speed Steps
{CV_29_CONFIG, CV29_F0_LOCATION}, // Short Address 28/128 Speed Steps
// {CV_29_CONFIG, CV29_EXT_ADDRESSING | CV29_F0_LOCATION}, // Long Address 28/128 Speed Steps
{CV_DECODER_MASTER_RESET, 0},
{CV_To_Store_SET_CV_Address, SET_CV_Address&0xFF }, // LSB Set CV Address
{CV_To_Store_SET_CV_Address+1,(SET_CV_Address>>8)&0x3F }, //MSB Set CV Address
};
uint8_t FactoryDefaultCVIndex = 0;
@@ -86,7 +105,7 @@ void setup()
// Setup which External Interrupt, the Pin it's associated with that we're using and enable the Pull-Up
Dcc.pin(0, 2, 0);
// Call the main DCC Init function to enable the DCC Receiver
Dcc.init( MAN_ID_DIY, 100, FLAGS_OUTPUT_ADDRESS_MODE | FLAGS_DCC_ACCESSORY_DECODER, 0 );
Dcc.init( MAN_ID_DIY, 600, FLAGS_OUTPUT_ADDRESS_MODE | FLAGS_DCC_ACCESSORY_DECODER, CV_To_Store_SET_CV_Address);
}
void loop()
{
@@ -94,7 +113,7 @@ void loop()
Dcc.process();
}
extern void notifyDccAccTurnoutOutput( uint16_t Addr, uint8_t Direction, uint8_t OutputPower ) {
if ( Addr >= This_Decoder_Address && Addr < This_Decoder_Address+17) //Controls This_Decoder_Address+16
digitalWrite( ledpins[Addr-This_Decoder_Address], Direction );
if ( Addr >= Accessory_Address && Addr < Accessory_Address+17) //Controls This_Decoder_Address+16
digitalWrite( ledpins[Addr-Accessory_Address], Direction );
}