To begin with, I have limited knowledge of coding so please dont use heavy programming terms because i get confused
Im basically trying to transfer the value of one variable to another variable in another function (using pointers maybe?). So in one function, i want to store the value of a variable into memory and then call on that memory in the main loop and assign it to another variable. how do i do this? i tried to return two variables in my function and read that its not possible. tried using pointers but im having trouble.
#include <Servo.h>
Servo index1;
int flexPin_1 = A1; //read flex sensor
void setup() {
Serial.begin(115200);
index1.attach(9); //finger mservo
}
void loop() {
int finger1 = constrain_flex_hiLo(flexPin_1, 3,16);
int finger1_servo = *p;
Serial.print(finger1); Serial.print(" "); Serial.print(finger1_servo); index1.write(finger1_servo);
Serial.println();
delay(5);
}
int constrain_flex_hiLo(int flexPin, int lo, int hi){
int finger = analogRead(flexPin);
finger = constrain(finger, lo, hi);
int fingerServo = map(finger, lo,hi, 0,180);
int *p = &fingerServo;
return finger;
}