I have a Duemilanove that i am playing with to control fan and a water pump for an intercooler.
I wont rave on about it, but i am testing this out on a bench with a pot (as a temp input) LED x 2 (as my fan and pump outputs, and a switch (which would be a pressure switch).
i uploaded the (if statement conditional) from the examples library.
i played with the values and could turn on one LED with the POT.
then i added some code for a second led and drove it with the pot HAPPY DAYS.
then i changed the code so i could turn on an LED once the POT had reached a set value and also once the switch had been closed. IE if pot > VALUE, AND switch HIGH, write LED HIGH. if only it was that easy.
so right now i cant work out how to use the AND function. this is the first time in years ive played with a micro (they just sit on my bench for months) and im becoming reminded as to why i avoid them like the plague.
I don't see any switch code or "and" function. Did you upload the right code?
/*
Conditionals - If statement
This example demonstrates the use of if() statements.
It reads the state of a potentiometer (an analog input) and turns on an LED
only if the LED goes above a certain threshold level. It prints the analog value
regardless of the level.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 13 to ground
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 17 Jan 2009
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/IfStatement
*/
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13; // 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 > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
}
// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability
}
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13; // pin that the LED is attached to
const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
const int switchPin = 02; // input switch
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode (switchPin, INPUT);
// 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 > threshold, && switchPin HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
}
// IVE TRIED THE FOLLOWING CODE IN PLACE OF WHAT IS ABOVE. ALL I GET IS ( expected')' before numeric constant/AND)
// if (analogValue > threshold, AND switchPin HIGH)
// if (analogValue > threshold, AND switchPin == HIGH)
// if ((analogValue > threshold), 'AND' (switchPin HIGH))
// if (analogValue > threshold, && switchPin HIGH)
// print the analog value:
Serial.println(analogValue);
delay(1); // delay in between reads for stability
}
Please go back and edit your post to include "code tags" so your code will be appropriately formatted. There are instructions for this in the sticky posts at the top of the forum.
What you are doing is referred to as "shotgunning". But you missed the barn this time. Have you considered consulting the reference, available in the help tab of the IDE?
AARG i went to the reference section, i couldnt find anything on AND, surely AND is used by you guys when you want multiple things to happen/line up before something else can happen?
f111:
AARG i went to the reference section, i couldnt find anything on AND, surely AND is used by you guys when you want multiple things to happen/line up before something else can happen?
oh yeah i saw that this morning in an earlier fit of rage. i tried various forms of the code shown but still get (expected ')' before numerical something something)
What is wrong with my code, how the hell am i supposed to use the AND function ? ive been pouring through the arduino cookbook, google, coffee grinds,,,,,, anything
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 > threshold, && switchPin HIGH) { <THIS BIT HERE fails during compile.
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
// IVE TRIED THE FOLLOWING CODE IN PLACE OF WHAT IS ABOVE. ALL I GET IS ( expected')' before numeric constant/AND)
// if (analogValue > threshold, AND switchPin HIGH)
// if (analogValue > threshold, AND switchPin == HIGH)
// if ((analogValue > threshold), 'AND' (switchPin HIGH))
// if (analogValue > threshold, && switchPin HIGH)
What is wrong with my code, how the hell am i supposed to use the AND function ? ive been pouring through the arduino cookbook, google, coffee grinds,,,,,, anything
The fact that there are hundreds of thousands of programmers who know C and don't have trouble using a logical AND suggests you're doing something wrong in your search. First, there is no AND function...it is a logical operator, so perhaps that's where you should start looking.