user16629: Hello i am trying to reverse a dc motor direction upon hitting either limit switch. but noting is working can some one point me in right direction. all example i find use stepper motors and step count.
const int sw2 = 2;          //Up Limit switch
const int sw3 = 3;          //Down Limit switch
const int ic1_2 = 8;        //TA8409S IN2
const int ic1_1 = 9;        //TA8409S IN1
const int enable = 10;      //TA8409S Enable (motor)
int sw2State = 0;
int sw3State = 0;

void setup() {
  pinMode(sw2, INPUT_PULLUP);
  pinMode(sw3, INPUT_PULLUP);
  pinMode(ic1_1, OUTPUT);
  pinMode(ic1_2, OUTPUT);
  pinMode(enable, OUTPUT);
  digitalWrite(enable, 1);
  Serial.begin(9600);
}

void loop() {
  tilt_up();
}

void tilt_up()
{
Serial.print("up Started\n");
  digitalWrite(ic1_1, LOW);
  digitalWrite(ic1_2, HIGH);
  sw2State = digitalRead(sw2);
  if (digitalRead(sw2State == LOW)) {
    tilt_down();
    Serial.print("sw2 pressde\n");
  }
}

void tilt_down()
{
  Serial.print("down Started\n");
  digitalWrite(ic1_1, HIGH);
  digitalWrite(ic1_2, LOW);
  sw3State = digitalRead(sw3);
  if (digitalRead(sw3State == LOW)) {
    tilt_up();
    Serial.print("sw3 Pressed\n");
  }
 }


user10794: void loop() {
  tilt_up();
}

void tilt_up()
{
...
  if (digitalRead(sw2State == LOW)) {
    tilt_down();
...
  }
}

...

void tilt_down()
{
...
  if (digitalRead(sw3State == LOW)) {
    tilt_up();
...
  }
 }

You are recursing here. loop calls tilt_up which eventually calls tilt_down which calls tilt_up and so on until you - rather quickly - run out of RAM.
Rewrite so that you are not doing that.

Also see what @MikaelPatel told you in your other question. You have the brackets in the wrong place.
  if (digitalRead(sw2State == LOW)) {

should be:
  if (digitalRead(sw2State) == LOW) {


user10214: If you want to reverse the movement you sould remember where you are going. This, along with the brackets correction suggested by @MikaelPatel and @NickGammon, leads to this code:
boolean moving_up = true;

void loop() {
    if (moving_up)
        tilt_up();
    else
        tilt_down();
}

void tilt_up()
{
    digitalWrite(ic1_1, LOW);
    digitalWrite(ic1_2, HIGH);
    if (digitalRead(sw2State) == LOW) {
        moving_up = false;
        Serial.println("sw2 Pressed");
        Serial.println("down Started");
    }
}

void tilt_down()
{
    digitalWrite(ic1_1, HIGH);
    digitalWrite(ic1_2, LOW);
    sw3State = digitalRead(sw3);
    if (digitalRead(sw3State) == LOW) {
        moving_up = true;
        Serial.println("sw3 Pressed");
        Serial.println("up Started");
    }
}


16629: <p>Hello i am trying to reverse a dc motor direction upon hitting either limit switch. but noting is working can some one point me in right direction. all example i find use stepper motors and step count.</p>

<pre><code>const int sw2 = 2;          //Up Limit switch
const int sw3 = 3;          //Down Limit switch
const int ic1_2 = 8;        //TA8409S IN2
const int ic1_1 = 9;        //TA8409S IN1
const int enable = 10;      //TA8409S Enable (motor)
int sw2State = 0;
int sw3State = 0;

void setup() {
  pinMode(sw2, INPUT_PULLUP);
  pinMode(sw3, INPUT_PULLUP);
  pinMode(ic1_1, OUTPUT);
  pinMode(ic1_2, OUTPUT);
  pinMode(enable, OUTPUT);
  digitalWrite(enable, 1);
  Serial.begin(9600);
}

void loop() {
  tilt_up();
}

void tilt_up()
{
Serial.print("up Started\n");
  digitalWrite(ic1_1, LOW);
  digitalWrite(ic1_2, HIGH);
  sw2State = digitalRead(sw2);
  if (digitalRead(sw2State == LOW)) {
    tilt_down();
    Serial.print("sw2 pressde\n");
  }
}

void tilt_down()
{
  Serial.print("down Started\n");
  digitalWrite(ic1_1, HIGH);
  digitalWrite(ic1_2, LOW);
  sw3State = digitalRead(sw3);
  if (digitalRead(sw3State == LOW)) {
    tilt_up();
    Serial.print("sw3 Pressed\n");
  }
 }
</code></pre>
 10794: <pre><code>void loop() {
  tilt_up();
}

void tilt_up()
{
...
  if (digitalRead(sw2State == LOW)) {
    tilt_down();
...
  }
}

...

void tilt_down()
{
...
  if (digitalRead(sw3State == LOW)) {
    tilt_up();
...
  }
 }
</code></pre>

<p>You are recursing here. <code>loop</code> calls <code>tilt_up</code> which eventually calls <code>tilt_down</code> which calls <code>tilt_up</code> and so on until you - rather quickly - run out of RAM.</p>

<p>Rewrite so that you are not doing that.</p>

<hr>

<p>Also see what @MikaelPatel told you in <a href="https://arduino.stackexchange.com/questions/19852/">your other question</a>. You have the brackets in the wrong place.</p>

<pre><code>  if (digitalRead(sw2State == LOW)) {
</code></pre>

<p>should be:</p>

<pre><code>  if (digitalRead(sw2State) == LOW) {
</code></pre>
 10214: <p>If you want to reverse the movement you sould remember where you are going. This, along with the brackets correction suggested by @MikaelPatel and @NickGammon, leads to this code:</p>

<pre><code>boolean moving_up = true;

void loop() {
    if (moving_up)
        tilt_up();
    else
        tilt_down();
}

void tilt_up()
{
    digitalWrite(ic1_1, LOW);
    digitalWrite(ic1_2, HIGH);
    if (digitalRead(sw2State) == LOW) {
        moving_up = false;
        Serial.println("sw2 Pressed");
        Serial.println("down Started");
    }
}

void tilt_down()
{
    digitalWrite(ic1_1, HIGH);
    digitalWrite(ic1_2, LOW);
    sw3State = digitalRead(sw3);
    if (digitalRead(sw3State) == LOW) {
        moving_up = true;
        Serial.println("sw3 Pressed");
        Serial.println("up Started");
    }
}
</code></pre>
