user16910: I recently got to work with Arduino and I want to get parallel input from 5 LDRs and at the same instance I need to light a LED corresponding to that LDR if the resistance got high. 
I read about a finite state machine, but I couldn't understand how it works.
Is it the only way for this type of problem or are there any other way? 

user13432: You do not need parallel processing or finite-state machines for that:
// Vector with digital pin numbers for LEDs (with resistor to ground)
const int LED_MAX = 5;
const int LED[LED_MAX] = { 2, 3, 4, 5, 6 };

// Vector with analog pin numbers for LDR (with pullup resistor)
const int LDR_MAX = 5;
const int LDR[LDR_MAX] = { A0, A1, A2, A3, A4 };

// Analog value or lower when to light the LED
const int THRESHOLD = 200;

void setup()
{
   // All LED pins should be digital output pins
   for (int i = 0; i < LED_MAX; i++) 
     pinMode(LED[i], OUTPUT);
}

void loop()
{
   // Read all LDRs and set LED pins according to threshold
   for (int i = 0; i < LDR_MAX; i++)
     digitalWrite(LED[i], analogRead(LDR[i]) < THRESHOLD);
}

But if you really want to describe this as multiple tasks you could use the Simple Scheduler library:
#include <Scheduler.h>

const int THRESHOLD = 200;    

template<int LED> void setup()
{
   pinMode(LED, OUTPUT);
}

template<int LED, int LDR> void loop()
{
   digitalWrite(LED, analogRead(LDR) < THRESHOLD);
   yield();
}

void setup()
{
   Scheduler.start(setup<2>, loop<2, A0>);
   Scheduler.start(setup<3>, loop<3, A1>);
   Scheduler.start(setup<4>, loop<4, A2>);
   Scheduler.start(setup<5>, loop<5, A3>);
   Scheduler.start(setup<6>, loop<6, A4>);
}

void loop()
{
   yield();
}


16910: <p>I recently got to work with Arduino and I want to get parallel input from 5 LDRs and at the same instance I need to light a LED corresponding to that LDR if the resistance got high. </p>

<p>I read about a finite state machine, but I couldn't understand how it works.</p>

<p>Is it the only way for this type of problem or are there any other way? </p>
 13432: <p>You do not need parallel processing or finite-state machines for that:</p>

<pre><code>// Vector with digital pin numbers for LEDs (with resistor to ground)
const int LED_MAX = 5;
const int LED[LED_MAX] = { 2, 3, 4, 5, 6 };

// Vector with analog pin numbers for LDR (with pullup resistor)
const int LDR_MAX = 5;
const int LDR[LDR_MAX] = { A0, A1, A2, A3, A4 };

// Analog value or lower when to light the LED
const int THRESHOLD = 200;

void setup()
{
   // All LED pins should be digital output pins
   for (int i = 0; i &lt; LED_MAX; i++) 
     pinMode(LED[i], OUTPUT);
}

void loop()
{
   // Read all LDRs and set LED pins according to threshold
   for (int i = 0; i &lt; LDR_MAX; i++)
     digitalWrite(LED[i], analogRead(LDR[i]) &lt; THRESHOLD);
}
</code></pre>

<p>But if you really want to describe this as multiple tasks you could use the <a href="https://github.com/mikaelpatel/Arduino-Scheduler" rel="nofollow">Simple Scheduler library</a>:</p>

<pre><code>#include &lt;Scheduler.h&gt;

const int THRESHOLD = 200;    

template&lt;int LED&gt; void setup()
{
   pinMode(LED, OUTPUT);
}

template&lt;int LED, int LDR&gt; void loop()
{
   digitalWrite(LED, analogRead(LDR) &lt; THRESHOLD);
   yield();
}

void setup()
{
   Scheduler.start(setup&lt;2&gt;, loop&lt;2, A0&gt;);
   Scheduler.start(setup&lt;3&gt;, loop&lt;3, A1&gt;);
   Scheduler.start(setup&lt;4&gt;, loop&lt;4, A2&gt;);
   Scheduler.start(setup&lt;5&gt;, loop&lt;5, A3&gt;);
   Scheduler.start(setup&lt;6&gt;, loop&lt;6, A4&gt;);
}

void loop()
{
   yield();
}
</code></pre>
