I guess I hate coding.
So this potentio meter reading is jumping all over the place.
the One on the left is the Raw Potentiometer value
```ino
-122 122 687
-120 120 684
-56 56 522
-121 121 686
-124 124 692
-57 57 524
-123 123 690
-120 120 683
14 Replies
So what are all the numbers?
Post the code your useing to read the pot
@TheStudier
´´´ino int motSpeedPin=3;
int speed;
int speed2;
int xPin=A0;
int xVal;
int leftPin=5;
int leftVal;
int rightPin=4;
int rightVal;
void setup() {
Serial.begin(9600);
pinMode(motSpeedPin,OUTPUT);
pinMode(leftPin,OUTPUT);
pinMode(rightPin,OUTPUT);
pinMode(xPin,INPUT);
}
void loop() {
// step one step:
xVal=analogRead(xPin);
speed2=map(xVal,505,1023,50,255);
speed=speed2*(-1);
Serial.print(speed);
Serial.print(" ");
Serial.print(speed2);
Serial.print(" ");
Serial.println(xVal);
if(xVal>530){
analogWrite(motSpeedPin,speed2);
digitalWrite(leftPin,LOW);
digitalWrite(rightPin,HIGH);
}
if(xVal<515){
analogWrite(motSpeedPin,speed);
digitalWrite(leftPin,HIGH);
digitalWrite(rightPin,LOW);
}
delay(100);
}
the code
Your mapping it incorrectly. Just print xval. And remove all the other mess. Just comment the rest out and print that out with no input. So we can see how much its changing please
Also realize. This is a science.
You can't just slap thing together and expect: 1 to learn. 2 to work. 3 to get repeatable results without giving repeating input.
So you need to approach this systematically.
@TheStudier
Also fix your code formatting.
thanjs a lot
Let me know what the just raw value is. And no math or nothing. And mo moving the pot just let it sit and take like 10 samples please.@TheStudier
So the potentio meter here is at the "0-position"
but it reads this:
23
23
23
22
24
26
27
28
28
27
27
28
29
28
28
0
29
28
So like every few seconds it goes to 0
This only happens when I put this code in "speed = map(xVal,0,522,255,0);"
It works fine without this
This is why I asked again for the RAW data please.
Because that map is no good.
@TheStudier
I just need to see the raw data; just serial print out the analog read with the wiper somewhere in the middle, not being touched.
Get it?
517
518
518
517
517
518
517
517
517
518
those are the raw values from the middle
works perfectly without the map
like I said
Ok so your pots fine now fix your map.
speed2=map(xVal,0,1023,0,255);
Now set that and print out that output.517
518
518
518
518
518
517
516
517
Ok we should be printing out speed2 now
got it kinda working
thanks a lot for helping
Thats my goal verify the componunt is working within reason. Then get you reset on a path with level footing. So you can make progress.
If you took/take anything I said/say as talking down. Or insulting or anything. Please dont.
I simply need a direct responce to what I am attempting to do as fast as possible. So I can assist you as best as I can and as efficiently as I can.
If the pot proven to be defective or say wireing messed up or what ever we would had a great spot for farther analysis.
Also in the arduino ide. Ctrl and T key should auto format your code so it looks better.
😉
okay tjanks again