Blackfin:
I based my code on yours and your limited description of what's going on.
In your code, if the LDR "reads" more than 500 the relay1 pin is set "high", otherwise the relay1 pin is set "low":
if(LDRValue>500)
digitalWrite(relay1,HIGH );
else
digitalWrite(relay1,LOW );
That is emulated in the first two states of the state machine:
case ST_WAIT_PART:
if( LDRValue > 500 )
{
//LDR shows something there; turn on relay1
digitalWrite( relay1, HIGH );
stateRelays = ST_PART_PRESENT;
}//if
break;
case ST_PART_PRESENT:
if( LDRValue <= 500 )
{
//part has passed; turn off relay 1 and turn on relay 2
//set up for timing relay 2 on time
digitalWrite( relay1, LOW );
digitalWrite( relay2, HIGH );
timeRelays = timeNow;
stateRelays = ST_TIME_RLY2;
}//if
break;
I assumed the LDR reads less than 500 when the part passes over the LDR. In state 2, the relay1 pin is set low and the relay2 pin is set high. It should stay high for 250mS and then go low:
case ST_TIME_RLY2:
//relay 2 stays on for RELAY2_TIME mS. When that time has passed turn it off
//and return to state waiting for another part
if( (timeNow - timeRelays) < RELAY2_TIME )
return;
digitalWrite( relay2, LOW );
stateRelays = ST_WAIT_PART;
break;
You don't say what "momentary" is so I guessed at 250mS.
In your last post you say:
You're right, this is confusing.
1) How did your original code operate relay 1?
2) To me, the terms "open" and "off" mean the same thing when applied to SPST-NO relays (again, another assumption on my part because your post was non-specific.)
3) What does the serial monitor output of the LDR say? Does it make sense?
4) How do you have your relays wired? Does a high on the pin energize the coil or de-energize it?
If you want more help you're going to have to be more clear and explain your setup better. I tried.
Blackfin:
I based my code on yours and your limited description of what's going on.
In your code, if the LDR "reads" more than 500 the relay1 pin is set "high", otherwise the relay1 pin is set "low":
if(LDRValue>500)
digitalWrite(relay1,HIGH );
else
digitalWrite(relay1,LOW );
That is emulated in the first two states of the state machine:
case ST_WAIT_PART:
if( LDRValue > 500 )
{
//LDR shows something there; turn on relay1
digitalWrite( relay1, HIGH );
stateRelays = ST_PART_PRESENT;
}//if
break;
case ST_PART_PRESENT:
if( LDRValue <= 500 )
{
//part has passed; turn off relay 1 and turn on relay 2
//set up for timing relay 2 on time
digitalWrite( relay1, LOW );
digitalWrite( relay2, HIGH );
timeRelays = timeNow;
stateRelays = ST_TIME_RLY2;
}//if
break;
I assumed the LDR reads less than 500 when the part passes over the LDR. In state 2, the relay1 pin is set low and the relay2 pin is set high. It should stay high for 250mS and then go low:
case ST_TIME_RLY2:
//relay 2 stays on for RELAY2_TIME mS. When that time has passed turn it off
//and return to state waiting for another part
if( (timeNow - timeRelays) < RELAY2_TIME )
return;
digitalWrite( relay2, LOW );
stateRelays = ST_WAIT_PART;
break;
You don't say what "momentary" is so I guessed at 250mS.
In your last post you say:
You're right, this is confusing.
1) How did your original code operate relay 1?
2) To me, the terms "open" and "off" mean the same thing when applied to SPST-NO relays (again, another assumption on my part because your post was non-specific.)
3) What does the serial monitor output of the LDR say? Does it make sense?
4) How do you have your relays wired? Does a high on the pin energize the coil or de-energize it?
If you want more help you're going to have to be more clear and explain your setup better. I tried.
Sorry I am very new to alot of electronics and coding so thank you for bearing with me. ill try to be more specific. the original code was meant to close relay1 (applys power to the motor). it seams that with the current code you wrote it rests at ST_PART_PRESENT with relay 2 set to high which closes the relay (applys power to the solenoid). what i am going for with the code is when a part passes over the ldr and no light is present i would like relay1 to close (apply power to the motor) and when the part passes through the rollers on the machine and past the ldr thus exposing it to light i would like to open relay1 (removing power from motor) and close relay2 for about 1000ms (applying power to the solenoid and ejecting the part) and then return to both relays open waiting for another part to pass over the ldr. and again thank you very much for your time and help.