nee dat ik geen 1Gb haal weet ik, de betreffende kaartjes gaan niet verder dan 10Mb, maar dat is al 100x sneller dan de 100Kb van I2C.
Toch nog één ding.
nl de CBUS.
Ik snap ook niet waarom elke firma zijn eigen bus moet uitvinden.
/* A program do control railroad semaphores from the Dutch Railways (NS) system 1946 Copyright (C) Meino de Graaf, all rights reserved This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.*/#include <Servo.h>#include <Wire.h>#include <NS_Seinstelsel46.h>#define I2C_BASE 8#define I2C_CONTROLLERS 2#define I2C_BEZETMELDER_ID 8#define I2C_SEINCONTROL1_ID 9#define I2C_SEINCONTROL2_ID 10#define I2C_SEINCONTROL3_ID 11//// ID that defines this specific instance of the controller.// It's actual value is established during setup and is based on some jumpers//int i2cId = 0;//// Table with all active turnouts//const int nrOfTurnouts = 12;Turnout turnouts[nrOfTurnouts] ={ Turnout(1), Turnout(2), Turnout(3), Turnout(4), Turnout(5), Turnout(6), Turnout(7), Turnout(8), Turnout(9), Turnout(10), Turnout(11), Turnout(12)};//// Table of all defined semaphores//const int nrOfSemaphores = 7;Semaphore semaphores[nrOfSemaphores] = { //------------------- Semaphore 55 on controller 2 --------------------------// Semaphore(CONTROLLER(2), SEMAPHORE(55), NO_STOP_DELAY, new Route(TURNOUT(10), new Route(TURNOUT(11), // Turnout 10 straight new Route(SEMAPHORE(58)), // Turnout 11 Straight SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 11 Diverting SPEED_STOP), SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 10 diverting SPEED_STOP), SEIN46_EENHOOG, new RGLed(PWM_PIN(13), INTENSITY(255), PWM_PIN(44), INTENSITY(160))), //------------------- Semaphore 56 on controller 3 --------------------------// Semaphore(CONTROLLER(3), SEMAPHORE(56), NO_STOP_DELAY, new Route(TURNOUT(8), new Route(TURNOUT(9), // Turnout 8 straight new Route(SEMAPHORE(60)), // Turnout 9 straight SPEED_MIDDLE, new Route(TURNOUT(10), // Turnout 9 diverting new Route(ROUTE_BARRED), // Turnout 10 straight SPEED_STOP, new Route(TURNOUT(11), // Turnout 10 diverting new Route(SEMAPHORE(58),SPEED_LOW,DANGER), SPEED_LOW, new Route(ROUTE_BARRED), SPEED_STOP), SPEED_LOW), SPEED_LOW), SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 8 diverting SPEED_STOP), SEIN46_EENHOOG, new RGLed(PWM_PIN(4), INTENSITY(18), PWM_PIN(5), INTENSITY(20))), //------------------- Semaphore 57 on controller 3 --------------------------// Semaphore(CONTROLLER(3), SEMAPHORE(57), NO_STOP_DELAY, new Route(TURNOUT(8), new Route(ROUTE_BARRED), // Turnout 8 straight SPEED_STOP, new Route(TURNOUT(9), // Turnout 8 diverting new Route(SEMAPHORE(60)), // Turnout 9 straight SPEED_LOW, new Route(TURNOUT(10), // Turnout 9 diverting new Route(ROUTE_BARRED), // Turnout 10 straight SPEED_STOP, new Route(TURNOUT(11), // Turnout 10 diverting new Route(SEMAPHORE(58),SPEED_LOW,DANGER), SPEED_LOW, new Route(ROUTE_BARRED), SPEED_STOP), SPEED_LOW), SPEED_LOW), SPEED_LOW), SEIN46_EENHOOG, new RGLed(PWM_PIN(6), INTENSITY(5), PWM_PIN(7), INTENSITY(6))), //------------------- Semaphore 58 (Dummy) ----------------------------------// Semaphore(58), //------------------- Semaphore 60 (Dummy) ----------------------------------// Semaphore(60), //------------------- Semaphore 66 on controller 1 --------------------------// Semaphore(CONTROLLER(1), SEMAPHORE(66), NO_STOP_DELAY, new Route(Turnout(2), new Route(TURNOUT(3), // Turnout 2 straight new Route(SEMAPHORE(55), SPEED_MIDDLE),// Turnout 3 straight SPEED_HIGH, new Route(TURNOUT(4), // Turnout 3 diverting new Route(ROUTE_BARRED), // Turnout 4 straight SPEED_STOP, new Route(TURNOUT(5), // Turnout 4 diverting new Route(SEMAPHORE(56)), // Turnout 5 straight SPEED_MIDDLE, new Route(SEMAPHORE(57)), // Turnout 5 diverting SPEED_LOW), SPEED_MIDDLE), SPEED_MIDDLE), SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 2 diverting SPEED_STOP), SEIN46_DRIEHOOG, new RGBLed(PWM_PIN(2),INTENSITY(18),PWM_PIN(3),INTENSITY(15),PWM_PIN(4),INTENSITY(9)), new RGBLed(PWM_PIN(5),INTENSITY(20),PWM_PIN(6),INTENSITY(22),PWM_PIN(7),INTENSITY(9)), new RGBLed(PWM_PIN(8),INTENSITY(21),PWM_PIN(9),INTENSITY(14),PWM_PIN(10),INTENSITY(9))), //------------------- Semaphore 67 on controller 3 --------------------------// Semaphore(CONTROLLER(3), SEMAPHORE(67), DELAY_STOP, new Route(TURNOUT(4), new Route(TURNOUT(5), // Turnout 4 straight new Route(SEMAPHORE(56)), // Turnout 5 straight SPEED_HIGH, new Route(SEMAPHORE(57)), // Turnout 5 diverting SPEED_LOW), SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 4 diverting SPEED_STOP), ARMSEIN_VERTAKKING, new ArmServo(PWM_PIN(11), 25, 104, 66), new ArmServo(PWM_PIN(12), 23, 50, 93), new WhiteLed(PWM_PIN(13), INTENSITY(60))), // (blok 14)};//// A function that executes whenever data is received from the bus// this function is registered as an interupt event, see setup()// It's purpose is to analyze the received event (Signal or turnout) and// update the proper element in the semaphore table or turnout table.//void receiveI2CEvent(int howMany){ unsigned int x = Wire.read(); // receive byte as an integer unsigned int dccId = x / 2; unsigned int dccState = x % 2; // // Find the proper turnout detector with the matching address // and sets its state. // if (Turnout::updateDirection(dccId, dccState)) { // // The dcc id matched a turnout no need to try the semaphores // return; } else { // // the dcc id didn't match a turnout, so try the semaphores // Semaphore::updateState(dccId, dccState); }}//// Pins used to define the ID of this controller// It is used to filter out all semaphores which aren't controlled by// this instance of the SeinController//#define PIN_ID_1 51#define PIN_ID_2 52#define PIN_ID_3 53void setup(){ // // Based on which pin is connected to ground, the controller ID is established // i2cId = 0; pinMode(PIN_ID_1, INPUT_PULLUP); pinMode(PIN_ID_2, INPUT_PULLUP); pinMode(PIN_ID_3, INPUT_PULLUP); if (!digitalRead(PIN_ID_1)) i2cId = 1; else if (!digitalRead(PIN_ID_2)) i2cId = 2; else if (!digitalRead(PIN_ID_3)) i2cId = 3; // // Tell the semaphore control where to find its turnouts and semaphores // and initialize the whole shebang // Semaphore::init(i2cId, nrOfTurnouts, turnouts, nrOfSemaphores, semaphores); // // Start the I2C communication // Wire.begin(I2C_BASE + i2cId); // join i2c bus Wire.onReceive(receiveI2CEvent); // register event handler}void loop(){ // // Scan all semaphores for updates in states and routes and change their // image if necessary // Semaphore::loop();}
Turnout turnouts[nrOfTurnouts] ={ Turnout(1), // Wissel met dcc adres 1 …....};
Semaphore semaphores[nrOfSemaphores] = {…...};
Semaphore(CONTROLLER(1), SEMAPHORE(66), NO_STOP_DELAY,
new Route(Turnout(2), new Route(TURNOUT(3), // Turnout 2 straight new Route(SEMAPHORE(55), SPEED_MIDDLE),// Turnout 3 straight SPEED_HIGH, new Route(TURNOUT(4), // Turnout 3 diverting new Route(ROUTE_BARRED), // Turnout 4 straight SPEED_STOP, new Route(TURNOUT(5), // Turnout 4 diverting new Route(SEMAPHORE(56)), // Turnout 5 straight SPEED_MIDDLE, new Route(SEMAPHORE(57)), // Turnout 5 diverting SPEED_LOW), SPEED_MIDDLE), SPEED_MIDDLE), SPEED_HIGH, new Route(ROUTE_BARRED), // Turnout 2 diverting SPEED_STOP),
SEIN46_DRIEHOOG,
new RGBLed(PWM_PIN(2),INTENSITY(18),PWM_PIN(3),INTENSITY(15),PWM_PIN(4),INTENSITY(9)), new RGBLed(PWM_PIN(5),INTENSITY(20),PWM_PIN(6),INTENSITY(22),PWM_PIN(7),INTENSITY(9)), new RGBLed(PWM_PIN(8),INTENSITY(21),PWM_PIN(9),INTENSITY(14),PWM_PIN(10),INTENSITY(9))),
void setup(){ // // Based on which pin is connected to ground, the controller ID is established // i2cId = 0; pinMode(PIN_ID_1, INPUT_PULLUP); pinMode(PIN_ID_2, INPUT_PULLUP); pinMode(PIN_ID_3, INPUT_PULLUP); if (!digitalRead(PIN_ID_1)) i2cId = 1; else if (!digitalRead(PIN_ID_2)) i2cId = 2; else if (!digitalRead(PIN_ID_3)) i2cId = 3; // // Tell the semaphore control where to find its turnouts and semaphores // and initialize the whole shebang // Semaphore::init(i2cId, nrOfTurnouts, turnouts, nrOfSemaphores, semaphores); // // Start the I2C communication // Wire.begin(I2C_BASE + i2cId); // join i2c bus Wire.onReceive(receiveI2CEvent); // register event handler}
void receiveI2CEvent(int howMany){ unsigned int x = Wire.read(); // receive byte as an integer unsigned int dccId = x / 2; unsigned int dccState = x % 2; // // Find the proper turnout detector with the matching address // and sets its state. // if (Turnout::updateDirection(dccId, dccState)) { // // The dcc id matched a turnout no need to try the semaphores // return; } else { // // the dcc id didn't match a turnout, so try the semaphores // Semaphore::updateState(dccId, dccState); }}
void loop(){ // // Scan all semaphores for updates in states and routes and change their // image if necessary // Semaphore::loop();}
void analogWrite(uint8_t pin, int val){ else if (val == 255) { digitalWrite(pin, HIGH); }