I have a program, which should actually be correct, but I'm sure there are some mistakes in there, cause otherwise it would work. I will write programm in here.
int pinOut1 = 4; //LED1
int pinOut2 = 5; //LED2
int pinOut3 = 6; //LED3
int pinOut4 = 9; //This is an output which leads to input pinIn2 so that code works only if input2 is active (see more in code below)
int pinIn1 = 7; //PullUP Input for the button, which (must) activate random number down below
int pinIn2 = 8; //Input that gets Voltage signal form Output pinOut4
int ran_num; //A random number from 20-22 (20,23)
void setup()
{
Serial.begin(9600);
pinMode(pinOut1, OUTPUT);
pinMode(pinOut2, OUTPUT);
pinMode(pinOut3, OUTPUT);
pinMode(pinOut4, OUTPUT);
pinMode(pinIn1, INPUT);
pinMode(pinIn2, INPUT);
}
void loop()
{
if(digitalRead(pinIn1 = true)) {(digitalWrite(pinOut4, true));} //Whenever button (input1) is pressed -> the outpu4 (must) activate and leads Voltage signal to input2 (somehow output4 always has 5V, no matter button is pressed or no)
else if (digitalRead(pinIn1 = false)&&digitalRead(pinIn2 = true)) {ran_num = random(20,23); Serial.println(ran_num); delay(50); (digitalWrite)(pinOut4, false);}
//When button (input1) is no longer pressed & input2 is still getting Voltage signal -> Serial.print random number 20-22 (20,23) and deactivate outpu4
if(ran_num == 20) {
digitalWrite(pinOut1, true);
digitalWrite(pinOut2, false);
digitalWrite(pinOut3, false);
}
if(ran_num == 21) {
digitalWrite(pinOut1, false);
digitalWrite(pinOut2, true);
digitalWrite(pinOut3, false);
}
if(ran_num == 22) {
digitalWrite(pinOut1, false);
digitalWrite(pinOut2, false);
digitalWrite(pinOut3, true);
}
}
sorry im new in this site, gotta learn abit how to provide my thoughts correctly.
The programm:
whenever the Button is pressed, code must generate a random number form 20 to 22 and serial print it and when the number is for example 20 than 1 of 3 leds must be true while others must be false. and the random number must be generated every time i press button. Thats the whole idea of program. if you want more info about it i wrote some more information how exactly it must work in program itselfe.
but whenever i press button it doesnt do anything, and if i delete the buttons form program, they blink randomly forever.
Thank you for answer, i will try to switch all = with == and see if it does work.
1 more thing, i have tested the voltage with multimeter and it shows 5V for the input. I think i have to check it somehow differently if my pins actually read them or not.
The code addresses two inputs, the schematic only has one input.
You have explained that you have connected pinIn1 to output4 (in order to make the code work). Why did you do that? Both input and output values are known to the processor.
While I am right here, I will say that a more common switch arrangement is to wire the switch bewteen the input pin and ground, and place the resistor between the input pin and 5 volts.
This is called pulled-up, and means your switch will read LOW when pressed, and HIGH when not pressed.
that is something i usualy do, because i dont have like in SPS any Noticer function so i do it so that only if the pin is active... (meanwhile in SPS i write only if the Noticer is active...)
i tried also writing
bool Merker1; //Translated from German Merker is the Noticer
SPS is a big industrial factory programming device with a lot of pins.
siemens SPS, I am master programmer of SPS, but Arduino is harder, so it is difficult for me to program it. Please don't scream at me for not knowing everything in it, otherwise I wouldn't ask here for some help.
Up to now I hadn't read your code too closely or worried about what you are up to.
It seems the program you present is some testing for a larger idea.
As @anon57585045 says, it makes no sense to use an output to control an input - all that can stay inside, so to speak.
Which is why that are called inputs and outputs. Iam sure the same thing obtains in SAS.
Perhaps it makes sense in some way with exactly what you are aiming for, but I think you would find the same trick odd if it was done on your more familiar territory.