Blackfin:
const int pinInput1 = A0;
const int pinInput2 = A1;
const int pinInput3 = A2;
//
const int pinRelay = 7;
//depending on how your relay is wired
//you may need to reverse these
#define RELAY_ON HIGH
#define RELAY_OFF LOW
void setup()
{
Serial.begin(9600);
//
pinMode( pinInput1, INPUT );
pinMode( pinInput2, INPUT );
pinMode( pinInput3, INPUT );
//
pinMode( pinRelay, OUTPUT );
digitalWrite( pinRelay, RELAY_OFF );
}
void loop()
{
static unsigned long
timeRelay = 0;
unsigned long
timeNow;
float
v1, v2, v3;
int
a1, a2, a3;
//update every 50mS
timeNow = millis();
if( timeNow - timeRelay >= 50 )
{
timeRelay = timeNow;
//read the analog channels
a1 = analogRead( pinInput1 );
a2 = analogRead( pinInput2 );
a3 = analogRead( pinInput3 );
//convert to floating point voltages
//for easy compares
v1 = (float)a15.0/1023.0;
Serial.print( "V1 : ");Serial.println(v1,2);
v2 = (float)a25.0/1023.0;
Serial.print( "V2 : ");Serial.println(v2,2);
v3 = (float)a3*5.0/1023.0;
Serial.print( "V3 : ");Serial.println(v3,2);
//check the thresholds
//If analog input pin A0 is between 2-3 volts and
//A1 is greater than 2.5 volts and
//A2 is greater than 3 volts
//it will send a signal from output pin 7 to
//operate a relay shield.
if( (v1 >= 2.0 && v1 <= 3.0) &&
(v2 > 2.50) &&
(v3 > 3.0 ) )
{
//turn on the relay
digitalWrite( pinRelay, RELAY_ON );
Serial.println( "Relay on" );
}//if
else
{
//turn off the relay
digitalWrite( pinRelay, RELAY_OFF );
Serial.println( "Relay off" );
}//else
Serial.println();
}//if
}//loop
I've had a read and a play with your code, It basically does what I want and I am greatful for the help, but I did run into a problem.
When one of the input wires was disconnected from the board, (any of the 3 inputs), the relay would start to go on and off randomly,
I played with the code, sometimes making it worse but not eliminating it, but have found the analog inputs already have a voltage across them as soon as the board is powered up which may be affecting it.
Also noticed the voltage across all pins would change when a voltage was applied to any input, almost like it was bleeding through some how.
I don't know whether that's normal, but would think not, maybe I have a dud board.
But thank you once again, the sketch you gave me has given me a good head start