How to make a RS latch?


hi everybody,

i've spent years program plcs , have discovered arduino. want learn , understand how make own programs , not copy , paste has been done others.
i start small , easy programs , try increase difficulty slowly. i'm stuck.

here want do:
i have 3 inputs connected 3 switches. each input controls own output (a led), plus output common 3 inputs , last input reset common output.
when 1 input high, corresponding led blink , common led inputs blink.
when input going low, both led off.

for working, succeeded it. don't know if it's correct way works.

now , when common led blinking, want switch off pressing button , led stay off when button released.
and if input goes high, output led on common led reset press button, , on.

with plc easy using rs latches, here, i'm lost.

here code:
code: [select]


void loop(){
loop1();
loop2();
loop3();
loop4();
}
 
void loop1(){
 
 input1state = digitalread(input1);

 if (input1state == high) {    
 
 unsigned long currentmillis = millis();

 if(currentmillis - previousmillis > interval) {

 previousmillis = currentmillis;  

 if (led1state == low)
 led1state = high;
 else
 led1state = low;

 digitalwrite(led1, led1state);
 }
 }
 else {
 digitalwrite(led1, low);
 }
}

void loop2(){
 input2state = digitalread(input2);

 if (input2state == high) {    
 
 unsigned long currentmillis = millis();

 if(currentmillis - previousmillis > interval) {
 previousmillis = currentmillis;  

 if (led2state == low)
 led2state = high;
 else
 led2state = low;

 digitalwrite(led2, led2state);
 }
}
 else {
 digitalwrite(led2, low);
 }
}

void loop3(){
 input3state = digitalread(input3);

 if (input3state == high) {    
 
 unsigned long currentmillis = millis();

 if(currentmillis - previousmillis > interval) {
 previousmillis = currentmillis;  

 if (led3state == low)
 led3state = high;
 else
 led3state = low;

 digitalwrite(led3, led3state);
 }
}
 else {
 digitalwrite(led3, low);
 }
}

void loop4(){

 input1state = digitalread(input1);
 input2state = digitalread(input2);
 input3state = digitalread(input3);
 resetstate = digitalread(reset);

 if (input1state | input2state | input3state == high) {    

 unsigned long currentmillis = millis();

 if(currentmillis - previousmillis > interval) {
   previousmillis = currentmillis;  

   if (led4state == low)
     led4state = high;
   else
     led4state = low;

   digitalwrite(led4, led4state);
 }
 }
    else {
   digitalwrite(led4, low);
 
 }
 }





i'm listening comments, i'm here learn  ;)

code: [select]
if (input1state | input2state | input3state == high)
there | operator , there || operator. different things.
http://arduino.cc/en/reference/boolean
http://arduino.cc/en/reference/bitwiseand

it looks want this:
code: [select]
if(input1state == high || input2state == high || input3state == high)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > How to make a RS latch?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums