- Wed Jun 12, 2013 10:05 pm
#160443
Having difficulty with the Sparkfun RTL-09877 Serial LCD
Using a potentiometer, I would like the coordinates to be displayed on the serial lcd, in real time.
For example, if the potentiometer is at 0 i would like to have the lcd display that number. If i turned the pot in any direction, where I leave the pot setting is the coordinate i would like displayed (using the coding of: 0, 1023, 0, 179)
Can anyone give me some insight as to what I will need to do..
Here is the code i am using - this portion of the program will turn 4 servos attached to the 4 potentiometers which I am speaking of.
PLEASE NOTE THAT THE CODING to make the servos operate is working fine, its just the coding to get the information from the pots to the serial lcd is where the problem lies.
//Beginning of Code
#include <Servo.h>
const int pan1 = 3; // first servo
const int tilt1 = 5; // second servo
const int pan2 = 6; // third servo
const int tilt2 = 9; // fourth servo
const int potpan1 = A0; // Pot 1 Vertical signal
int val0;
const int pottilt1 = A1; // Pot 2 Horizontal signal
int val1;
const int potpan2 = A2; // Pot 3 Select signal
int val2;
const int pottilt2= A3; // Pot4 Vertical signal
int val3;
int servoVal[4]; // variable to read the value from the analog pin
Servo mypan1; // create servo object to control a servo
Servo mytilt1; // create servo object to control a servo
Servo mypan2; // create servo object to control a servo
Servo mytilt2; // create servo object to control a servo
void setup()
{
// Servo
mypan1.attach(pan1); // attaches the servo
mytilt1.attach(tilt1); // attaches the servo
mypan2.attach(pan2); // attaches the servo
mytilt2.attach(tilt2); // attaches the servo
// Inizialize Serial
Serial.begin(57600);
}
void loop()
{
//outputPotentiometers(); // Read and output pot values
val0 = analogRead(potpan1); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
outputPotentiometers(); // Read and output potentiometer values
mypan1.write(val0); // sets the servo position according to the scaled value
val1 = analogRead(pottilt1); // i added
val1 = map(val1, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mytilt1.write(val1); // i added
val2 = analogRead(potpan2); // i added
val2 = map(val2, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mypan2.write(val2); // i added
val3 = analogRead(pottilt2); // i added
val3 = map(val3, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mytilt2.write(val3); // i added
delay(1);
}
void outputPotentiometers() // Display potentiometer Values
{
Serial.print("P1~3: ");
Serial.print((val0));
Serial.print("\t");
Serial.print(" T1~5: ");
Serial.print((val1));
Serial.print("\t");
Serial.print(" P2~6: ");
Serial.print((val2));
Serial.print("\t");
Serial.print(" T2~9: ");
Serial.println((val3));
Serial.print("\t");
}
Using a potentiometer, I would like the coordinates to be displayed on the serial lcd, in real time.
For example, if the potentiometer is at 0 i would like to have the lcd display that number. If i turned the pot in any direction, where I leave the pot setting is the coordinate i would like displayed (using the coding of: 0, 1023, 0, 179)
Can anyone give me some insight as to what I will need to do..
Here is the code i am using - this portion of the program will turn 4 servos attached to the 4 potentiometers which I am speaking of.
PLEASE NOTE THAT THE CODING to make the servos operate is working fine, its just the coding to get the information from the pots to the serial lcd is where the problem lies.
//Beginning of Code
#include <Servo.h>
const int pan1 = 3; // first servo
const int tilt1 = 5; // second servo
const int pan2 = 6; // third servo
const int tilt2 = 9; // fourth servo
const int potpan1 = A0; // Pot 1 Vertical signal
int val0;
const int pottilt1 = A1; // Pot 2 Horizontal signal
int val1;
const int potpan2 = A2; // Pot 3 Select signal
int val2;
const int pottilt2= A3; // Pot4 Vertical signal
int val3;
int servoVal[4]; // variable to read the value from the analog pin
Servo mypan1; // create servo object to control a servo
Servo mytilt1; // create servo object to control a servo
Servo mypan2; // create servo object to control a servo
Servo mytilt2; // create servo object to control a servo
void setup()
{
// Servo
mypan1.attach(pan1); // attaches the servo
mytilt1.attach(tilt1); // attaches the servo
mypan2.attach(pan2); // attaches the servo
mytilt2.attach(tilt2); // attaches the servo
// Inizialize Serial
Serial.begin(57600);
}
void loop()
{
//outputPotentiometers(); // Read and output pot values
val0 = analogRead(potpan1); // reads the value of the potentiometer (value between 0 and 1023)
val0 = map(val0, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
outputPotentiometers(); // Read and output potentiometer values
mypan1.write(val0); // sets the servo position according to the scaled value
val1 = analogRead(pottilt1); // i added
val1 = map(val1, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mytilt1.write(val1); // i added
val2 = analogRead(potpan2); // i added
val2 = map(val2, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mypan2.write(val2); // i added
val3 = analogRead(pottilt2); // i added
val3 = map(val3, 0, 1023, 0, 179); // i added
outputPotentiometers(); // Read and output potentiometer values
mytilt2.write(val3); // i added
delay(1);
}
void outputPotentiometers() // Display potentiometer Values
{
Serial.print("P1~3: ");
Serial.print((val0));
Serial.print("\t");
Serial.print(" T1~5: ");
Serial.print((val1));
Serial.print("\t");
Serial.print(" P2~6: ");
Serial.print((val2));
Serial.print("\t");
Serial.print(" T2~9: ");
Serial.println((val3));
Serial.print("\t");
}