@Don re: Questions
Hi Don,
Quote:
What would be the best way to learn C++ as it applies to the Arduino chips?
There are hundreds of ways to approach this, depending on your background. I usually recommend learning the language in the context of using the Arduino, rather than as a separate computer language. Two good places to start are with the language reference:
https://www.arduino.cc/en/Reference/HomePage
/> and by looking through the library examples:
https://www.arduino.cc/en/Tutorial/LibraryExamples
/> Start with examples that you may be interested in or familiar with -- like servos. All of these can be found through the general tutorial page:
https://www.arduino.cc/en/Tutorial/HomePage
If you feel compelled to look at the C/C++ language independently, I like the O'Reilly "Nutshell" books, but they are usually not geared for beginners. The C Programming Language Book by Brian Kernighan and Dennis Ritchie was the best reference I used when learning C.
Quote:
In the sketch for 8 servos with a slaved output pin, the syntax for setting individual outputs to "1" or "0" as power on defaults eludes me. Would setting each pin happen in the same place as the tests you setup on power up?
First, remember that decoders (and base stations) usually power up assuming all functions are set to zero or off. So if you power up the decoder (with servos) assuming functions set to anything but zero/off your decoder will not be set the way your base station/throttle thinks it is.
With that said, servos are initially set in the setup() code. Look for the loop that starts:
for ( i=0; i < numfpins; i++) {
cv_value = Dcc.getCV( 30+(i*5)) ;
//Serial.print(" cv_value: ");
//Serial.println(cv_value, DEC) ;
switch ( cv_value ) {
This goes through each possible function pin: for ( i=0; i < numfpins; i++)
and then keys off the the first of 5 CV values stored for each function.
case 2: //servo is for a function that is a servo control.
This code reads the assumed current position, stopping position, starting position, and change increment (regulating speed) for every servo.
switch ( i ) { picks the particular sevo and this code:
case 0: servo0.attach(FunctionPin0); // attaches servo on pin to the servo object
ftn_queue.inuse = 1;
servo0.write(ftn_queue.start_value);
for (t=0; t< servo_start_delay; t++) {SoftwareServo::refresh();delay(servo_init_delay);}
break;
moves the servo to its starting position, slowly, regardless of where it was at last power down.
Quote:
I would like to setup a run once or a run until reset procedure to center servos for initial mounting/setup on a layout or a way to setup each servo as it is installed
OK. If you want to "center" the servos for initial mounting, that is easy. For each servo you want to set, find the table in the sketch that starts with:
CVPair FactoryDefaultCVs [] =
{
{CV_ACCESSORY_DECODER_ADDRESS_LSB, Accessory_Address},
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
{CV_DECODER_MASTER_RESET, 0},
{CV_To_Store_SET_CV_Address, SET_CV_Address},
{CV_To_Store_SET_CV_Address+1, 0},
{30, 2}, //F0 Config 0=On/Off,1=Blink,2=Servo,3=Double LED Blink
{31, 1}, //F0 Rate Blink=Eate,PWM=Rate,Servo=Rate
{32, 28}, //F0 Start Position F0=0
{33, 140}, //F0 End Position F0=1
{34, 28}, //F0 Current Position
{35, 2}, //F1 Config 0=On/Off,1=Blink,2=Servo,3=Double LED Blink
{36, 1}, // Rate Blink=Eate,PWM=Rate,Servo=Rate
{37, 28}, // Start Position Fx=0
{38, 140}, // End Position Fx=1
{39, 28}, // Current Position
...
find the function pin associated with your servo(s)-- look at F1 here. 28 is the default start value in a range of 0-180, so choose 85. 140 is the default stop value in a range of 0-180, so substitue 95. and SAVE the values in your sketch and reload your decoder. Now when the decoder powers up it will be near the middle of the throw! You can change the start and stop values of the appropriate CV's with your throttle until you are happy, BUT WRITE DOWN THE START/STOP VALUES YOU SET, and then you can save them in your sketch. When you set the CV's with your throttle, THEY ARE SAVED in the decoder IF you removed the "//" in the #define DECODER_LOADED code as I advise.
// ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
//#define DECODER_LOADED
I would recommend you put the values you set for your decoder in the skecth and save it under a separate name specific for your decoder.
'Hope this helps. Have fun! 
Best Regards,
Geoff