LPC1768 - Green LED when LDR sees light, Red LED when LDR is covered
This is not a full answer but there seem to be a few problems with your code. 
You use

g_led.write(1);


and further down

green.write(0);


Should green be g_led?

Your routine also turns both LEDs on on each call to Task5 and then if value &gt;= 0.4 turns the red off again. That may explain your blinking.

As pointed out in the comment, sloppy indentation doesn't help in trying to debug this. Get into the habit of always indenting your code properly as you go.



Try this:

while(tester.testRunning()) {
    float value = ldr.read(); //takes the reading from the LDR(Light Dependent Resistor)

    if(value &gt;= 0.4) {
        g_led.write(1); // Green off.
        r_led.write(0); // Red on.
    } else {
        g_led.write(0); // Green on.
        r_led.write(1); // Red off.
        //wait_ms(2);   // not required
    }
}