So this is my problem! I have two codes- one for my linear potentiometer (Code 1) and one for my actuator and force sensor ( Code 2). Individually they work fine on their own! Merging them together they don’t- the issue that I have is on the serial monitor for the linear potentiometer isnt showing me the correct values. I would really appreciate it if someone could tell me what I am doing wrong and how I can fix it!
CODE 1 - Linear Potetiometer code ALONE
int sensorValue=A1;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A1);
Serial.println(sensorValue/12.7875);
delay(300);
}
//
CODE 2 - Linear Actuator Code with force sensor
#include <Servo.h>
Servo myServo;
byte forcePin = A0;
byte servoPin = 9;
byte ledPin = 13;
byte servoPos = 0;
int countsFor10 = 200; // find how many ADC counts = 10 force units
boolean forceApplied = false;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
myServo.attach(servoPin);
}
void loop()
{
if (forceApplied == false) // only run once until force is applied
{
while (analogRead(forcePin) <= countsFor10)
{
Serial.println(analogRead(forcePin));
delay (100);
myServo.write(servoPos);
delay(100); // change delay to suit
servoPos++;
}
forceApplied = true;
digitalWrite(ledPin, HIGH);
Serial.println("endrun");
Serial.println(analogRead(forcePin));
byte servoPos=0;
}
}
CODE 3 -My attempt to merge
#include <Servo.h>
Servo myServo;
byte forcePin = A0;
byte sensorValue=A1;
byte servoPin = 9;
byte ledPin = 13;
byte servoPos = 0;
int countsFor10 = 200; // find how many ADC counts = 10 force units
boolean forceApplied = false;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
myServo.attach(servoPin);
}
void loop()
{
Serial.println(sensorValue/12.7875);
delay(300);
if (forceApplied == false) // only run once until force is applied
{
while (analogRead(forcePin) <= countsFor10)
{
Serial.println(analogRead(forcePin));
delay (100);
myServo.write(servoPos);
delay(100); // change delay to suit
servoPos++;
}
forceApplied = true;
digitalWrite(ledPin, HIGH);
Serial.println("endrun");
Serial.println(analogRead(forcePin));
byte servoPos=0;
}
}