i have a problem with my code I have if code but when i go to run it does’t do anything. The Mega2560
R3 board is brand new nothing wrong with it and so is the joystick and 8x8 MAX72XX Matrix everything is hooked up properly
here is the code
Note:no errors pop up when i have the code verified
#include <LedControl.h>
const int SW_pin = 2; // digital pin connected to switch output
const int Xpin = 0; // analog pin connected to X output
const int Ypin = 1; // analog pin connected to Y output
LedControl lc=LedControl(12,10,11,1);
void setup() {
// put your setup code here, to run once:
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values /
lc.setIntensity(0,8);
/ and clear the display */
lc.clearDisplay(0);
}
void loop(){
if (Xpin==0,Ypin==0); //if the joystick goes to (0,0) then it will tell the 8x8 matrix to light (0,0)
else ; //this was put here to see if the if code even works
{
digitalWrite(13,LOW);
delay(1000);
digitalWrite(13,HIGH);
}{
byte a[2]{B10000000,B10000000};
lc.setRow(0,0,a[1]);
digitalWrite(13,LOW);
}
}
the idea of the program is to have the joystick control the a light around the 8x8 screen
can anybody help me with this inconvenient problem
I doubt very much that the comma in this statement does what you think it does:
if (Xpin==0,Ypin==0);
Here you missed an '=' : byte a[2]{B10000000,B10000000};and it doesn't belong in a code block (although it may be allowed by the compiler). I am a little surprised that it compiled.
There are an infinite number of completely non-working programs that have a valid C syntax. The compiler will happily compile anything that follows the syntax rules. So passing a compilation is no indication of anything - only a failure to compile is useful for that.
And you almost certainly don’t want a ; after the else. Currently your code says if (something that makes no sense) then do nothing else still do nothing.
wildbill:
I have never seen that before. I was tempted to call BS, but figured that I'd better ask the compiler first and was pleased I did.
Is it a C++ thing? When did it happen?
Good questions!
And I would add why would you use it over including the = sign?
I accept it is shorter by one character, but that hardly seems a good reason.
pcbbc:
Good questions!
And I would add why would you use it over including the = sign?
I accept it is shorter by one character, but that hardly seems a good reason.
Indeed. I'm now curious about whether it means exactly the same thing.
the code works but not when i want it to i change the program a bit all it does is have 0,0 on the 8x8 is flickering it is completely ignoring the if and else code
Here is the new progarm #include <LedControl.h>
const int SWpin = 2; // digital pin connected to switch output
const int Xpin = 0; // analog pin connected to X output
const int Ypin = 1; // analog pin connected to Y output
LedControl lc=LedControl(12,10,11,1);
void setup() {
// put your setup code here, to run once:
pinMode(SWpin, INPUT);
digitalWrite(SWpin, HIGH);
Serial.begin(9600);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call /
lc.shutdown(0,false);
/ Set the brightness to a medium values /
lc.setIntensity(0,8);
/ and clear the display */
lc.clearDisplay(0);
}
void loop(){
if (Xpin==0&Ypin==0);//if the joystick goes to (0,0) then it will tell the 8x8 matrix to light (0,0)
else;{
byte a[2]{B00000000,B00000000};//if the joystick is not in the (0,0) position then it will be off
lc.setRow(0,0,a[1]);
}
{
byte a[2]{B10000000,B10000000};
lc.setRow(0,0,a[1]);
digitalWrite(13,LOW);
}
And you seem to have forgotten ever to READ the values of your input pins. Using the pin NUMBERS in your if statements isn't going to do you much good. Oh and & doesn't mean the same as &&. You need to use the right one.
All in all this code is an excellent demonstration of the fact that just because your code compiles doesn't mean that it's going to do anything useful.
Please read the post at the start of any forum , entitled "How to use this Forum".
OR http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.