mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-25 13:41:23 +01:00
Create mySetup.cpp_example.txt
Provide an example showing directives for HAL device configuration.
This commit is contained in:
parent
0d235b65d3
commit
425de3fcc7
139
mySetup.cpp_example.txt
Normal file
139
mySetup.cpp_example.txt
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
// Sample mySetup.cpp file.
|
||||||
|
//
|
||||||
|
// To use this file, copy it to mySetup.cpp and uncomment the directives and/or
|
||||||
|
// edit them to satisfy your requirements.
|
||||||
|
|
||||||
|
// Note that if the file has a .cpp extension it WILL be compiled into the build
|
||||||
|
// and the mySetup() function WILL be invoked.
|
||||||
|
//
|
||||||
|
// To prevent this, temporarily rename it to mySetup.txt or similar.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "IODevice.h"
|
||||||
|
#include "Turnouts.h"
|
||||||
|
#include "Sensors.h"
|
||||||
|
#include "IO_HCSR04.h"
|
||||||
|
|
||||||
|
|
||||||
|
// The #if directive prevent compile errors for Uno and Nano by excluding the
|
||||||
|
// HAL directives from the build.
|
||||||
|
#if !defined(IO_NO_HAL)
|
||||||
|
|
||||||
|
|
||||||
|
// Examples of statically defined HAL directives (alternative to the create() call).
|
||||||
|
// These have to be outside of the mySetup() function.
|
||||||
|
|
||||||
|
|
||||||
|
// The following directive defines a PCA9685 PWM Servo driver module.
|
||||||
|
// The parameters are:
|
||||||
|
// First Vpin=100
|
||||||
|
// Number of VPINs=16 (numbered 100-115)
|
||||||
|
// I2C address of module=0x40
|
||||||
|
|
||||||
|
//PCA9685 pwmModule1(100, 16, 0x40);
|
||||||
|
|
||||||
|
|
||||||
|
// The following directive defines an MCP23017 16-port I2C GPIO Extender module.
|
||||||
|
// The parameters are:
|
||||||
|
// First Vpin=164
|
||||||
|
// Number of VPINs=16 (numbered 164-179)
|
||||||
|
// I2C address of module=0x20
|
||||||
|
|
||||||
|
//MCP23017 gpioModule2(164, 16, 0x20);
|
||||||
|
|
||||||
|
|
||||||
|
// Alternative form, which allows the INT pin of the module to request a scan
|
||||||
|
// by pulling Arduino pin 40 to ground. Means that the I2C isn't being polled
|
||||||
|
// all the time, only when a change takes place. Multiple modules' INT pins
|
||||||
|
// may be connected to the same Arduino pin.
|
||||||
|
|
||||||
|
//MCP23017 gpioModule2(164, 16, 0x20, 40);
|
||||||
|
|
||||||
|
|
||||||
|
// The following directive defines an MCP23008 8-port I2C GPIO Extender module.
|
||||||
|
// The parameters are:
|
||||||
|
// First Vpin=300
|
||||||
|
// Number of VPINs=8 (numbered 300-307)
|
||||||
|
// I2C address of module=0x22
|
||||||
|
|
||||||
|
//MCP23017 gpioModule3(300, 8, 0x22);
|
||||||
|
|
||||||
|
|
||||||
|
// The following directive defines a PCF8574 8-port I2C GPIO Extender module.
|
||||||
|
// The parameters are:
|
||||||
|
// First Vpin=200
|
||||||
|
// Number of VPINs=8 (numbered 200-207)
|
||||||
|
// I2C address of module=0x23
|
||||||
|
|
||||||
|
//PCF8574 gpioModule4(200, 8, 0x23);
|
||||||
|
|
||||||
|
|
||||||
|
// Alternative form using INT pin (see above)
|
||||||
|
|
||||||
|
//PCF8574 gpioModule4(200, 8, 0x23, 40);
|
||||||
|
|
||||||
|
|
||||||
|
// The following directive defines an HCSR04 ultrasonic module.
|
||||||
|
// The parameters are:
|
||||||
|
// Vpin=2000 (only one VPIN per directive)
|
||||||
|
// Number of VPINs=1
|
||||||
|
// Arduino pin connected to TRIG=30
|
||||||
|
// Arduino pin connected to ECHO=31
|
||||||
|
// Minimum trigger range=20cm (VPIN goes to 1 when <20cm)
|
||||||
|
// Maximum trigger range=25cm (VPIN goes to 0 when >25cm)
|
||||||
|
// Note: Multiple devices can be configured by using a different ECHO pin
|
||||||
|
// for each one. The TRIG pin can be shared between multiple devices.
|
||||||
|
// Be aware that the 'ping' of one device may be received by another
|
||||||
|
// device and position them accordingly!
|
||||||
|
|
||||||
|
//HCSR04 sonarModule1(2000, 30, 31, 20, 25);
|
||||||
|
//HCSR04 sonarModule2(2001, 30, 32, 20, 25);
|
||||||
|
|
||||||
|
|
||||||
|
// The function mySetup() is invoked from CS if it exists within the build.
|
||||||
|
// It is called just before mysetup.h is executed, so things set up within here can be
|
||||||
|
// referenced by commands in mySetup.h.
|
||||||
|
|
||||||
|
void mySetup() {
|
||||||
|
|
||||||
|
// Alternative way of creating MCP23017, which has to be within the mySetup() function
|
||||||
|
// The other devices can also be created in this way. The parameter lists for the
|
||||||
|
// create() function are identical to the parameter lists for the declarations.
|
||||||
|
|
||||||
|
//MCP23017::create(180, 16, 0x21);
|
||||||
|
|
||||||
|
|
||||||
|
// Creating a Turnout
|
||||||
|
// Parameters: same as <T> command for Servo turnouts
|
||||||
|
// ID and VPIN are 100, sonar moves between positions 102 and 490 with slow profile.
|
||||||
|
// Profile may be Instant, Fast, Medium, Slow or Bounce.
|
||||||
|
|
||||||
|
//ServoTurnout::create(100, 100, 490, 102, PCA9685::Slow);
|
||||||
|
|
||||||
|
|
||||||
|
// DCC Accessory turnout
|
||||||
|
// Parameters: same as <T> command for DCC Accessory turnouts
|
||||||
|
// ID=3000
|
||||||
|
// Decoder address=23
|
||||||
|
// Decoder subaddress = 1
|
||||||
|
|
||||||
|
//DCCTurnout::create(3000, 23, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// Creating a Sensor
|
||||||
|
// Parameters: As for the <S> command,
|
||||||
|
// id = 164,
|
||||||
|
// Vpin = 164 (configured above as pin 0 of an MCP23017)
|
||||||
|
// Pullup enable = 1 (enabled)
|
||||||
|
|
||||||
|
//Sensor::create(164, 164, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// Way of creating lots of identical sensors in a range
|
||||||
|
|
||||||
|
//for (int i=165; i<180; i++)
|
||||||
|
// Sensor::create(i, i, 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user