Need help to set a register

Hey.

I am sitting this evning and came upon some small stuff for my model railroad, and I have 2 switchs when then first one is pressed and then released again I need an output to go HIGH until the second switch is activated.
Could anyone help me with that, I believe that I need to setup a register, and the when the first swicth is HIGH it will set the register a "1" and when the register is "1" the output is going to be HIGH until register is set to "0".

Hope that some one can help me.
And yes I am new to this and it is about 15 + years last time I made a program.

Regards RedOrder

This "switch" - is it what we in the UK call "points" ?

Can you post your code - digitalWrite usually works for most people in the Arduino world.

define the pins & stuff, then wire your switches to connent the pin to ground when pressed.

byte switch1 = 2;
byte switch2 = 3;
byte outputPin = 4;
void setup(){
pinMode (switch1, INPUT_PULLUP); // assumes you have IDE 1.0.1
pinMode (switch2, INPUT_PULLUP);
pinMode (outputPin, OUTPUT);
}
void loop(){
if (digitalRead(switch1) == 0)
{
digitalWrite( outputPin, HIGH);
}
if (digitalRead (switch2) == 0)
{
digitalWrite (outputPin, LOW);
}
} // end void loop

Well not much to see but this. So I hope that you are sitting down as you might break out in laughter LOL

const int mag1Pin = 2; // pin nummer hvor magnet switch 1 sidder
const int mag2Pin = 3; // pin nummer hvor magnet switch 2 sidder
const int relay1Pin = 13; // pin nummer hvor relay 1 til styring sidder

void setup() {
pinMode(mag1Pin, OUTPUT);
pinMode(mag2Pin, OUTPUT);
pinMode(relay1Pin, INPUT);
}

void loop(){
if (mag1Pin == HIGH){ Set a register high}
if (register == HIGH) {set relay1Pin == HIGH}
}

Regards RedOrder

What is your concept of a "register?

RedOrder:
Hey.

I am sitting this evning and came upon some small stuff for my model railroad, and I have 2 switchs when then first one is pressed and then released again I need an output to go HIGH until the second switch is activated.
Could anyone help me with that, I believe that I need to setup a register, and the when the first swicth is HIGH it will set the register a "1" and when the register is "1" the output is going to be HIGH until register is set to "0".

Hope that some one can help me.
And yes I am new to this and it is about 15 + years last time I made a program.

Regards RedOrder

This is pretty straight forward logic. Simple example:

if (digitalRead(buttonPinA) = 1) { digitalWrite(SomePin, 1); }
if (digitalRead(buttonPinB) = 1 && digitalRead(SomePin) = 1) { digitalWrite(SomePin, 0); }

Probably want to use a library or some external components to debounce or otherwise cleanup the button presses.

Simple example:

Code:
if (digitalRead(buttonPinA) = 1) { digitalWrite(SomePin, 1); }
if (digitalRead(buttonPinB) = 1 && digitalRead(SomePin) = 1) { digitalWrite(SomePin, 0); }

Simple, but incorrect example. Try “==”

Yeah, that's not gonna work

if (register == HIGH) {set relay1Pin == HIGH}

register is not defined, and relay1Pin is an input, so setting it high (with just 1 =, two == is testing its condition) will just turn on its internal pullup resistor.

Performing digitalWrite sets/clears an output register, which then goes through output drivers and shows up at a pin.
If you don't want a pin changing, then just set/clear a variable and act upon the state of that variable.

The register was what I use to use in the old days to set up some values for later use.
Bus I see the logic in what Crossroads have written, It makes sence,
So I think I will try that out and see where it gets me.
Otherwise I be back asking for help again.

Thx
Regards RedOrder

“Probably want to use a library or some external components to debounce or otherwise cleanup the button presses.”
Not needed - you only looking for it to change state once, then there is a delay in time until you get around to pressing the other button.
So the output may get written a couple of times - so what? You will only see the output change state and stay there since the same button is not being used to make it change state again.

RedOrder:
The register was what I use to use in the old days to set up some values for later use.
Bus I see the logic in what Crossroads have written, It makes sence,
So I think I will try that out and see where it gets me.
Otherwise I be back asking for help again.

Thx
Regards RedOrder

Today we call your 'old days register' a variable and you can define them and set them to any value you want for both immediate or later use.

Lefty