No, it was just 000000000000
Not even individual results on separate lines?
I'm up for any suggestions re tests I can perform to see if anything is happening.
How about answering the question in reply#22?
Sorry, I'm not sure how to do that. I know I'm out of my depth but every day I learn something new. Give me a some instruction and I'll get straight back to you in the morning.
The way you have written the debug prints, each value should be on a separate line on the serial monitor, but you have described them as all being on the same line:
If that's the case, the simplest reason I can think of to cause that would be a repeated processor reset, but if that's not the case, I can't think how all the results would be on the same line as you described, with the software you posted.
Hi, @doonie
Try this edit of your code.
I have slowed the loop down and repositioned the serial prints.
I have also added a serial print to the end of the setup(), to check that your project is not resetting.
int joystrick1 = A1;
int joystrick2 = A2;
int val1;
int val2;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
Serial.println("Setup Complete");
delay(500);
}
void loop()
{
// put your main code here, to run repeatedly:
int val1 = analogRead(joystrick1);
int val2 = analogRead(joystrick2);
Serial.print("Joystick1 Value= ");
Serial.print(val1);
Serial.print(" Joystick2 Value= ");
Serial.println(val2);
if (val1 > 1 && val1 < 490)
{
val1 = map(val1, 1, 490, 255, 0);
analogWrite(6, val1);
analogWrite(5, 0);
}
if (val1 > 530 && val1 < 1023)
{
val1 = map(val1, 530, 1023, 0, 255);
analogWrite(5, val1);
analogWrite(6, 0);
}
if (val1 > 491 && val1 < 529)
{
val1 = map(val1, 491, 529, 0, 0);
analogWrite(5, val1);
analogWrite(6, val1);
}
if (val2 > 1 && val2 < 490)
{
val2 = map(val2, 1, 490, 255, 0);
analogWrite(10, val2);
analogWrite(9, 0);
}
if (val2 > 530 && val2 < 1023)
{
val2 = map(val2, 530, 1023, 0, 255);
analogWrite(9, val2);
analogWrite(10, 0);
}
if (val2 > 491 && val2 < 529)
{
val2 = map(val2, 491, 529, 0, 0);
analogWrite(9, val2);
analogWrite(10, val2);
}
delay(250);
}
Tom...
Goodonya TomGeorge. There are some results, which to me is encouraging. I am very interested to see what you learn from those results as that may help me to understand what is going on. Hope the vid is clear enough for you to see.
Oh, I wish we could visit…
you’re soooo close!
Tom is about 3-1/2 hours from you, and I’m about 2 hours away.
Either one of us could have you jumping for joy within about 20-30 minutes of arriving !
Thanks mate. The time will come. You both must come visit. 300 yards to the pub. Three spare double beds and you can play with some of my stuff.
Hi, mate.
Thanks for the video.
The code is cycling as it should, but the two values should not change for just the axis of joystick.
Try this and tell me if it is still the same.
int joystrick1 = A1;
int joystrick2 = A2;
int val1;
int val2;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
Serial.println("Setup Complete");
delay(500);
}
void loop()
{
// put your main code here, to run repeatedly:
val1 = analogRead(joystrick1);
val1 = analogRead(joystrick1);
val2 = analogRead(joystrick2);
val2 = analogRead(joystrick2);
Serial.print("Joystick1 Value= ");
Serial.print(val1);
Serial.print(" Joystick2 Value= ");
Serial.println(val2);
if (val1 > 1 && val1 < 490)
{
val1 = map(val1, 1, 490, 255, 0);
analogWrite(6, val1);
analogWrite(5, 0);
}
if (val1 > 530 && val1 < 1023)
{
val1 = map(val1, 530, 1023, 0, 255);
analogWrite(5, val1);
analogWrite(6, 0);
}
if (val1 > 491 && val1 < 529)
{
val1 = map(val1, 491, 529, 0, 0);
analogWrite(5, val1);
analogWrite(6, val1);
}
if (val2 > 1 && val2 < 490)
{
val2 = map(val2, 1, 490, 255, 0);
analogWrite(10, val2);
analogWrite(9, 0);
}
if (val2 > 530 && val2 < 1023)
{
val2 = map(val2, 530, 1023, 0, 255);
analogWrite(9, val2);
analogWrite(10, 0);
}
if (val2 > 491 && val2 < 529)
{
val2 = map(val2, 491, 529, 0, 0);
analogWrite(9, val2);
analogWrite(10, val2);
}
delay(250);
}
Tom...
PS, About to finish work in 1 hour, them I'll be home.
Hi, mate.
Have you got your joystick connected as in this image?
Ignore using the brown wire, it is for the switch under the joystick I think.
I'll have a look when I get home.
Tom...
Tom.. !
You succumbed to a Frizzy !
— ok, it was for a good reason, small piece of a drawing (!)
What happened here !?
Maybe worth naming the pins too…
Wires are connected correctly, although on this joystick pos and neg are side by side then vert, horz and switch.
Serial monitor prints basically the same except this time it said set up complete first.
Seriously thanks for this.
By the way Tom, Peter Dalmaris, Tech Explorations, is going to organise a zoom meeting for Monday September 27 at 4 pm for one hour with a couple of internationals, himself, Michael and my own good self to talk about the crane, if you are interested. Michael can give you my email and I can then send the link if you like.
Cheers
Hi,
It was out of necessity, at work, quick cut and paste...
Tom...
Hi,
To be sure.. To be sure the analog channels were properly read.
Tom...
Hi,
Okay ,the thing is only one value should change for each axis.
It looks like only one axis of motion changes both analog changes, is that right.
Can you measure the voltage between A0 and gnd and move the joystick, find which axis changes the voltage and what the voltages are.
Then do the same with A1.
A0 voltage should only change with either fwd/back OR left/right.
Same for A1.
Tom...