I am attempting to wire a SPDT switch and am having a bit of trouble, namely that I cannot seem to get an signal out of either of my two analog pins.
Currently I am attempting to make my SPDT switch send a High Signal to one of two different analog in pins and in doing so. Have it rotate a servo motor in one of three positions 0 Degrees 90 Degrees and 180 Degrees.
/* This code is a test for a 3D printed Eye Mechanism and Eye Brow Mechanism this is my first really ever code writing Project I am using youtube.
Tutorials as well as the Stan Winston School tutorials. My Name is Bucky.
According to this paper The Human eye can rotate down vertialcally 30 Deg, and upwards 25deg and left to right 35 off of center
https://biology.stackexchange.com/questions/72511/what-are-the-max-angles-of-human-eyeball-rotation
refrences Nilheim Mechatromics Simplified Eye Mechanism Code
https://howtomechatronics.com/projects/arduino-rc-airplane-diy/
People and forum's that have helped Cathode on Twitter, Luci on Discord, The Arduino Forums members
The analog smoothing is to help with motor longevity, and from the servos twitching. When this was impletmented the Servos for X and Y began to act as one on the Y axis.
Turns out both values were over writing each other so a new set of values had to be created JoyYval and JoyXval these took the place of JoyY and JoyX. These new values
did were used for the real computing.The Previous Values were set as now place holders for reserving pins.
The analog smoothing is to help with motor longevity, and from the servos twitching. When this was impletmented the Servos for X and Y began to act as one on the Y axis.
Turns out both values were over writing each other so a new set of values had to be created JoyYval and JoyXval these took the place of JoyY and JoyX. These new values
did were used for the real computing.The Previous Values were set as now place holders for reserving pins. Newpotval = JoyY + Potval; was changed to Newpotval = JoyYval + Potval;
because the eyelids werent following the Y axis
*/
#include <Servo.h>
Servo ServoX;// Creates X axis Servo
Servo ServoY;// Creates Y axis Servo
Servo ServoUplid;// Creates upper Eye lid Servo
Servo ServoDownlid;// Creates Lower eyelid Servo
Servo ServoBrow;// Creates eyebrow servo
int JoyY =A1;// Joy Stick Y axis connected to Analog pin 1 and reserves that pin preventing it from being over written
int JoyX =A0;// Joystick X axis connect to analog pin 0 and reserves that pin preventing it from being over written
int JoyYval;// Deals with computing the Servo Movement for the joy stick Y value
int JoyXval;// deals with computing the servo movement for the Joy stick X value
int Potval; // the holding Value for eyelids
int Lidpot= A2 ; // the poteniometer for controlling the Eyelids
int Newpotval; // this creates a holding value for other servos
int Lidbutton= 13 ;//Button for Blinking the Eyelid PWM 13
const int lidnumreadings = 10; // sets the sample size for data
int lidreadings [lidnumreadings]; // the readings from analog input from the eye lid potentiometer
int lidreadIndex = 0;// index of the current reading
int lidtotal = 0;// running total;
//const int browbuttonlow = 7;
void setup() {
ServoX.attach (9);// Attaches X axis Servo to the PWM pin 9
ServoY.attach (10); // Attaches Y axis Servo to the PWM pin 10
ServoUplid.attach (11); // Attaches the Upper Eyelid Servo to the 11 PWM pin
ServoDownlid.attach (12);// Attaches the lower Eyelid Servo to the 12 PWM pin
ServoBrow.attach (8);// Attaches the Eyebrow servo to the PWM pin 8
Serial.begin (9600);
}
void loop() {
JoyXval = analogRead(JoyX);
JoyYval = analogRead(JoyY);
Potval = analogRead(Lidpot);
Lidbutton = digitalRead (13);
//Analog smoothing section for the Eyelid
lidtotal = lidtotal - lidreadings [lidreadIndex]; // subtract last reading
lidreadings [lidreadIndex] = analogRead (Lidpot);// sets lidreadings to equal whatever is being analog read from the eye lid potentiometer
lidtotal = lidtotal + lidreadings [lidreadIndex]; // add the reading to the total
lidreadIndex = lidreadIndex + 1; // advance to the next postion of the array
if (lidreadIndex >= lidnumreadings) {// if you are at the end of the array
lidreadIndex = 0;// loop back around to the begining
}
Potval = lidtotal / lidnumreadings;// calculates the average and makes the average be the potval
JoyXval = map(JoyXval, 0, 1023, 55, 125);//maps values to realistic range of motion this might need to be changed later for loss of movement through cable housing
JoyYval = map(JoyYval, 0, 1023, 60, 115);//maps value to realistic range of motion
Potval = map(Potval, 0, 1023, -20, 20);
Newpotval = JoyYval + Potval;
Newpotval = constrain(Newpotval, 0, 180);// limits Joy Stick Y axis from telling motor to move out of 180 deg
ServoX.write(JoyXval); // Writes the servo the signal
ServoY.write(JoyYval); // This line then writes servo motor Y the Angle Interger value
ServoUplid.write(Newpotval);//writes to the upper eyelid
ServoDownlid.write(Newpotval);// writes to the lower eyelid
// if then statements for blinking
if ( Lidbutton == HIGH ) {
ServoUplid.write (JoyY);
ServoDownlid.write (JoyY);
}
else {
ServoUplid.write(Newpotval);//writes to the upper eyelid
ServoDownlid.write(Newpotval);// writes to the lower eyelid
}
delay (50);
// Eye Brow 3 postion switch
if(A3==HIGH){
ServoBrow.write(0);
}
if(A4==HIGH){
ServoBrow.write(180);
}
if (A4==LOW){
ServoBrow.write (90);
}
// Serial Print stuff for trouble shooting
Serial.print(JoyXval);
Serial.print (",");
Serial.print(JoyYval);
Serial.print (",");
Serial.print (Newpotval);
Serial.print (",");
Serial.print(A4);
Serial.println (",");
}