Hello,
I recently completed, with some assistance from Coder27, Bill Abbot, Tony, and Mark Beckett the first part of my project ( http://www.element14.com/community/thread/23967?start=0&tstart=0 )
Now the second part - I am wanting to add a small 16 x 1 LCD to finish up my project (see coding below that I will be using)
I would like the LCD to simply show which direction a servo is pointing (as in degrees, such as 0°, 90°, 180°, 270°, or 360° or anywhere in between 0° to 360°)
Please be advised: I do know that arduino 1.0.4 has the LCD Scroll example, but I am sure I dont need the entire code they have. Also, my LCD is only 16 x 1, not x 2.
Thanks,
~Anna
******** BEGINNING OF CODE *************
#include <Servo.h>
const int pan1 = 3; // first servo
const int tilt1 = 5; // second servo
const int pan2 = 9; // third servo
const int tilt2 = 11; // fourth servo
const int potpan1 = A0; // Joystick 1 Vertical signal
int val0;
const int pottilt1 = A1; // Joystick 1 Horizontal signal
int val1;
const int potpan2 = A5; // Joystick 1 Select signal
int val2;
const int pottilt2= A3; // Joystick 2 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 joystick 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)
mypan1.write(val0); // sets the servo position according to the scaled value
//Serial.print("Value of PWM 3: ");
//Serial.println(val0);
//Serial.print("\t");
val1 = analogRead(pottilt1); // i added
val1 = map(val1, 0, 1023, 0, 179); // i added
mytilt1.write(val1); // i added
//Serial.print("Value of PWM 5: ");
//Serial.println(val1);
//Serial.print("\t");
val2 = analogRead(potpan2); // i added
val2 = map(val2, 0, 1023, 0, 179); // i added
mypan2.write(val2); // i added
//Serial.print("Value of PWM 6: ");
//Serial.println(val2);
//Serial.print("\t");
val3 = analogRead(pottilt2); // i added
val3 = map(val3, 0, 1023, 0, 179); // i added
mytilt2.write(val3); // i added
delay(20);
}
void outputPotentiometers() // Display Joystick Values
{
Serial.print("Pot Pan 1 on ~3: ");
Serial.print(analogRead(potpan1));
Serial.print("\t");
Serial.print(" Pot Tilt 1 on ~5: ");
Serial.print(analogRead(pottilt1));
Serial.print("\t");
Serial.print(" Pot Pan 2 on ~9: ");
Serial.print(analogRead(potpan2));
Serial.print("\t");
Serial.print(" Pot Tilt 2 on ~11: ");
Serial.println(analogRead(pottilt2));
Serial.print("\t");
}
********** END OF CODE *************

