hi there - is it me or the arduino, have been trying to write a program using the if command and two digitalwrite high. But it does not work. Is the Arduino capable of doing this eg
if x = 500
hi there - is it me or the arduino, have been trying to write a program using the if command and two digitalwrite high. But it does not work. Is the Arduino capable of doing this eg
if x = 500
It is if you write the statement correctly. The language reference (top of the page under Resources) can help there as can keeping your eyes open when looking at all the other code in the IDE examples or round here.
You can't just make up your own version of the language.
Steve
sthomas229:
hi there - is it me or the arduino, have been trying to write a program
Until you post your program we will have to assume it is you
...R
sorry got cut off ...some of you guys are too quick....had to wait 5 mins...
was writing
if{ x = (500)}
digitalWrite( 8, HIgh)
digitalWrite (11, HIGH)
Else
DigitalWrite ( 8, LOW)
Digitalwrite ( 11, LOW)
I know I have tried it badly
No output on pin 11, but output on pin 8
Have tried to swap them all around
a. please use code tag button (</> ) to insert code
b. there are some errors. Please post the whole error list of compilation
c. take a look at reference, "if"
I'll stick by my original advice. Can you find any other program with an if statement that looks like that?
And in this language capital letters are important - digitalWrite and DigitalWrite are NOT the same thing and neither are else and Else.
Steve
if{ x = (500)}
"==", not "=", () not {}
slipstick:
I'll stick by my original advice. Can you find any other program with an if statement that looks like that?And in this language capital letters are important - digitalWrite and DigitalWrite are NOT the same thing and neither are else and Else.
Steve
you have been told from post #2: go to top of page/recources
you have been told from post #4: take a look at reference, "if"
if (YouFollowTheseInstructions ==1){
YouBeHappy=1;
WeAreHappy=1;
}
else ExpectMoreHelp=0;
"YouFollowTheseInstructions" not declared in this scope
hi there - sorry to cause some much anger....full code below....
all I would like to know is if the arduini is capable of a writing tow digitalWrite in an if statement.
Have been looking at reference with the if statement ...
void setup() {
// initialize the LED pin as an output:
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode ( 11, OUTPUT); // main led
// initialize serial communications:
Serial.begin(9600);
}
void
loop() {
// read the value of the potentiometers:
int ti = analogRead(A4);
int y = analogRead(A3);
int x= analogRead(A5);
int tii = analogRead(A2);
// if the analog value is high enough, turn on the LED:
if (x > (511)) { //if for a4 pin
digitalWrite(2, HIGH);
digitalWrite(11, HIGH);
} else {
digitalWrite(2, LOW);
digitalWrite(11, LOW);
}
if (x < (450)) {
digitalWrite(3, HIGH);
digitalWrite(11, HIGH);
}else {
digitalWrite(3, LOW);
digitalWrite(11, LOW);
}
if (y > (600)) {
digitalWrite (4, HIGH);
digitalWrite(11, HIGH);
} else {
digitalWrite(4, LOW);
digitalWrite(11, LOW);
}
if (y < (475)) {
digitalWrite (5, HIGH);
digitalWrite(11, HIGH);
}else {
digitalWrite(5, LOW);
digitalWrite(11, LOW);
}
if (ti < (400)) {
digitalWrite (6, HIGH);
digitalWrite(11, HIGH);
}else {
digitalWrite(6, LOW);
digitalWrite(11, LOW);
}
if (ti > (800)) {
digitalWrite (7, HIGH);
digitalWrite(11, HIGH);
} else {
digitalWrite(7, LOW);
digitalWrite(11, LOW);
}
if (tii < (400)) {
digitalWrite (8, HIGH);
digitalWrite(11, HIGH);
}else {
digitalWrite(8, LOW);
digitalWrite(11, LOW);
}
if (tii > (600)) {
digitalWrite (9, HIGH);
digitalWrite(11, HIGH);
} else {
digitalWrite(9, LOW);
digitalWrite(11, LOW);
}
// print the analog value:
Serial.println(x);
delay(1500); // delay in between reads for stability
}
To make it easy for people to help you please modify your post and use the code button </>
so your code looks like this
and is easy to copy to a text editor. See How to use the Forum
Your code is too long for me to study quickly without copying to a text editor.
There is no limit to the amount of code that can be within an IF block.
...R
thank you that's all I wanted to know....will build a smaller version and then builted up