Okay, so I'm trying to make my own function instead of using the map() function by using the math behind it, described on the map() section on the site.
But I'm getting an error when I try to run the function that says "void value not ignored as it ought to be".
#include <Servo.h>
Servo myServo;
const int potPin = A0;
int angle;
void scale(int potVal, int scaleLow, int scaleHigh, int angleLow, int angleHigh) {
(potVal - scaleLow) * (angleHigh - angleLow) / (scaleHigh - scaleLow) + angleLow;
Serial.print("potVal: ");
Serial.print(potVal);
}
void setup() {
myServo.attach(9);
Serial.begin(9600);
}
void loop() {
angle = scale(analogRead(potPin), 0, 1023, 0, 179);
Serial.print(", angle: ");
Serial.print(angle);
myServo.write(angle);
delay(15);
}
system
March 11, 2016, 3:47pm
2
angle = scale(analogRead(potPin), 0, 1023, 0, 179);
"scale" doesn't return a value.
void scale(int potVal, int scaleLow, int scaleHigh, int angleLow, int angleHigh) {
(potVal - scaleLow) * (angleHigh - angleLow) / (scaleHigh - scaleLow) + angleLow;
Serial.print("potVal: ");
Serial.print(potVal);
}
In fact, it doesn't seem to do anything useful.
If you want it to return a value, change the function
int scale(int potVal, int scaleLow, int scaleHigh, int angleLow, int angleHigh) {
return (potVal - scaleLow) * (angleHigh - angleLow) / (scaleHigh - scaleLow) + angleLow;
}
That gives me a new error: return-statement with a value, in function returning 'void' [-fpermissive]
system
March 11, 2016, 4:48pm
5
Your scale() function bears a remarkable similarity to the map() function.