void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200){
fJa();
}else{
if (analogRead(A1) > 200) {
fWN();
}else{
if (analogRead(A2) > 200) {
fNein();
}
}
}
}
}
It only reacts to A0 not to A1 and A2.
Without else it still doesent work.
jurs
April 17, 2016, 3:46pm
2
Heginator:
void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200){
fJa();
}else{
if (analogRead(A1) > 200) {
fWN();
}else{
if (analogRead(A2) > 200) {
fNein();
}
}
}
}
}
It only reacts to A0 not to A1 and A2.
Without else it still doesent work.
Circuit schematics?
Have a look here to see the correct coding of the "if" in an "else if"; your curly brackets are misplaced.
Its just 3 Push Buttons connected to 3v3 with LEDs and pulldown resistors. The output of the buttons is also connectet to 3 transistors, wich are then connected to 3v3 and the 3 Analog inputs over a pulldown resistor.
JimboZA:
Have a look here to see the correct coding of the "if" in an "else if"; your curly brackets are misplaced.
what would be your suggestion
void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200){
fJa();
}else{
if (analogRead(A1) > 200) {
fWN();
}} else{
if (analogRead(A2) > 200) {
fNein();
}
}
}
}
this doesent work
If you look at the example on the man page, this...
}else{
if (.....)
.... should look like this:
}
else if (...)
{
(ie, the "else" and the "if" are together as "else if".
if (condition)
{
// code
}
else if (condition) // can have as many of these as you like
{
// code
}
else // notice there is no condition. it is not required to have an "else"
{
// This code runs if none of the previous conditions are met
}
this doesent work
If you press T (control and T) at the same time in the IDE, it's straight away clear what goes wrong; Below what it looks like after formatting has been applied.
void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200) {
fJa();
} else {
if (analogRead(A1) > 200) {
fWN();
}
} else {
if (analogRead(A2) > 200) {
fNein();
}
}
}
}
The second 'else' does not 'belong to' the second 'if'. The error message (to confirm)
sketch_apr17a:33: error: 'else' without a previous 'if'
} else {
^
exit status 1
'else' without a previous 'if'
void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200) {
fJa();
}
else if (analogRead(A1) > 200) {
fWN();
}
else if (analogRead(A2) > 200) {
fNein();
}
}
}
With this code it still wont react to A1 and A2
Actually you probably want to lose the "else" idea.
It only looks at the "else" if the original "if" failed.
Take the "else"s out and it should look at all the pins regardless of the state of the previous ones.
if (analogRead(A0) > 200) {
fJa();
}
if (analogRead(A1) > 200) { //<<<<<<<<<<<< lose the "else"
fWN();
void SWAbfrage() {
while ( AntW != 1) {
if (analogRead(A0) > 200) {
fJa();
}
if (analogRead(A1) > 200) {
fWN();
}
if (analogRead(A2) > 200) {
fNein();
}
}
}
still no rection
Put serial prints in to a) see what the values are and b) see if it's actually going into the right "if"s
Something like this....
void SWAbfrage() {
while ( AntW != 1) {
int dummy = analogRead(A0);
Serial.println(dummy);
if ( dummy > 200) {
Serial.print("in the dummy>200 if");
fJa();
JimboZA:
Put serial prints in to a) see what the values are and b) see if it's actually going into the right "if"s
0
0
0
298
in the dummy>200 if
It sends everything
the problem was in the while conditions
while ( AntW < 1) {
int dummy = analogRead(A0);
Serial.println(dummy);
if ( dummy > 200) {
Serial.print("in the dummy>200 if");
fJa();
}
int dummy1 = analogRead(A1);
Serial.println(dummy1);
if ( dummy1 > 200) {
Serial.print("in the dummy1>200 if");
fWN();
}
int dummy2 = analogRead(A2);
Serial.println(dummy2);
if ( dummy2 > 200) {
Serial.print("in the dummy2>200 if");
fNein();
}
}
}
in the functions fJa() fWN() and fNein() it changes the value of AntW
AntW = AntW + 1;
i guess before the change from "AntW != 1" to "AntW <1" it kept adding up to 2,3,4,5... wich then fits in the condition AntW != 1;
Moral of the story: when you have lots of variables and / or complicated ifs and whiles, use lots of Serial.print()s