Manuel Schreiner
Published © GPL3+

Maerklin 4316 Central

Turning Märklin 4316 into a DCC central? Deal!

AdvancedShowcase (no instructions)4 hours1,562
Maerklin 4316 Central

Things used in this project

Story

Read more

Schematics

Drawing Connecting Components

Drawing Connecting Components

Code

Digispark Code

C/C++
creating a differential protocol from the serial stream with timeout check
void setup() {
  // put your setup code here, to run once:
  pinMode(0, INPUT);
  pinMode(1, OUTPUT);
  digitalWrite(1,HIGH);
  pinMode(2,OUTPUT);
  pinMode(4,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  bool bLastState = false;
  volatile int Count = 0;
  for(;;)
  {
    Count++;
    if (digitalRead(0) != bLastState)
    {
        bLastState = !bLastState;
        digitalWrite(2,bLastState);
        digitalWrite(4,!bLastState);
        if (Count > 1000) 
        {
          digitalWrite(1,LOW);
        } else
        {
          digitalWrite(1,HIGH);
        }
        Count = 0;
    }
    if (Count > 1000) 
    {
      digitalWrite(1,LOW);
    }
  }
}

Credits

Manuel Schreiner
4 projects • 8 followers

Comments