Okay. I'm currentl;y very close to getting this to work. I can activate a relay according to an input from the cruise control switch.
But, its only one relay.
How can I set a "Range" for my analogValue figure? I've tried if (analogValue <990) and the relay switches on... great, but how do I get it to ignore signals higher than that?
I did try using AND in there, but that didnt work. I tried just adding the values like this - <990 >1000 but that didnt work.
What am I missing here? Google isnt really giving me an answer I can understand.
Here's the Sketch I'm using - currently just trying to activate one relay. Was wanting to use two relays and only one analog input.
*/
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 23; // pin that the LED is attached to
const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue < 990) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
}
// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability