Hi all I sometime ago Posted on using a Arduino to help run my model railway Layout Well I can now use software to help draw and run the layout even better however I have come stuck with the coding I have tried many different options and none seem to work I'm pretty sure soon as its pointed out ill go OH YH that was it. My current code I am trying to get to work is
#include <CMRI.h>
CMRI cmri;
int CT1 = 0;
int input =0;
int n = 0;
void setup() {
Serial.begin(9600, SERIAL_8N2); // SERIAL_8N2 to match what JMRI expects CMRI hardware to use
pinMode(13, OUTPUT);
pinMode(53, OUTPUT);
pinMode(52, OUTPUT);
digitalWrite(13,LOW);
digitalWrite(52,HIGH);
digitalWrite(53,HIGH);
pinMode(12, OUTPUT);
}
void loop() {
cmri.process();
// digitalWrite(52, cmri.get_bit(0));
//digitalWrite(53, cmri.get_bit(1));
if (cmri.get_bit(0));
{
if (n == 0)
{
if (CT1 == 0)
{
Point1A();
CT1 = 1;
RESET();
}
if (CT1 == 1)
{
Point1B();
CT1 = 0;
RESET();
}
}
}
}
void Point1A()
{
digitalWrite(52,LOW);
//cmri.set_bit(3, !digitalRead(12));
delay(500);
digitalWrite(52,HIGH);
}
void Point1B()
{
digitalWrite(53,LOW);
//cmri.set_bit(4, !digitalRead(12));
delay(500);
digitalWrite(53,HIGH);
}
void RESET()
{
//n = -1;
digitalWrite(13,LOW);
}
The idea is the bit number it gets and then depending on a couple of other variables it does the according actions. currently I just have the two input bouncing and no seem of control.
I am guessing here but I need to use a varable to get the bit number that is incoming (which i tried with a simple
(cmri.get_bit(n)
which is shown on the page for the library but still nothing
So in simple terms so we are all on the same page in this case Ill use bit 0 which is on the software address 1
1. Read incoming bit number eg cmri.get_bit(0)
2. Sets a variable.
3. Script reads what this variable is eg 0
4. Acts and checks the Next variable to find if the points is in position 1 or 2
5. Acts on that info throwing the point the correct way.
6. resets the variable in step 3 to stop the looping of this action
7. Wait for next incoming bit to act on
Hope it makes sense I did last time end up writing a good script to a control panel. this is my upgrade
this is the library
https://github.com/madleech/ArduinoCMRI