Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Simulating a PLC ladder diagram on arduino on: February 22, 2013, 11:32:40 am
Hi friends,

I was trying to do something like latching in ladder logic
and here is my result. Code is very simple because i am two months playing with Arduino. I like it.
     2                   3                    8

---||-----|--------||---------------( )
     8      |
---||-----|

     8                                       9
---||-------------------------------( )


Code:
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int led8 = 8;
int led9 = 9;
int led10 = 10;


int button2 = 0;
int button3 = 0;
int button4 = 0;
int button5 = 0;
int light8 = 0;
int light9 = 0;
int light10 = 0;

void setup()
{
  pinMode(pin2, INPUT);
  pinMode(pin3, INPUT);
  pinMode(pin4, INPUT);
  pinMode(pin5, INPUT);
  pinMode(led8, OUTPUT);
  pinMode(led9, OUTPUT);
  pinMode(led10, OUTPUT);
}

void loop()
{
  button2 = digitalRead(pin2);
  button3 = digitalRead(pin3);
  button4 = digitalRead(pin4);
  button5 = digitalRead(pin5);
  light8=digitalRead(led8);
  light9=digitalRead(led9);
  light10=digitalRead(led10);


  if(button2 == HIGH || light8 == HIGH && button3 == LOW)
  {
    digitalWrite(led8, HIGH);
  }
  else if (button3 == HIGH)
  {
    digitalWrite(led8, LOW);
  }

  if(light8 == HIGH && button4 == HIGH)
  {
    digitalWrite(led9, HIGH);
  }
  else if(light8 == LOW)
  {
    digitalWrite(led9, LOW);
  }
}

2  Development / Other Software Development / Documentation correction on: January 07, 2013, 03:08:38 pm
http://arduino.cc/en/Reference/BooleanVariables

in the last row the semicolon is missing

void loop()
{
  if (digitalRead(switchPin) == LOW)
  {  // switch is pressed - pullup keeps pin high normally
    delay(100);                        // delay to debounce switch
    running = !running;                // toggle running variable
    digitalWrite(LEDpin, running)      // indicate via LED
  }
}
Pages: [1]