Some updates:
- Got the main "tracking rail" for the bed edge built and programmed to return
- Began working on the actual following of the bed edge
Wiring:
In this photo, the connections between the servo and sensors are given. The push button and limit switch are connected to a "pull-up" resistor. The connections have been rearranged for organization in the past week.
Code: (uncommented)
#include <Servo.h>
int val;
int encoder0PinA = 12;
int encoder0PinB = 13;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
Servo finderServo;
int stopButton = 4;
int resetButton = 3;
int stopButtonValue = 0;
int resetButtonValue = 0;
int encoderRead()
{
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}
Serial.println (encoder0Pos);
}
encoder0PinALast = n;
}
void armIn()
{
finderServo.write(0);
}
void armOut()
{
finderServo.write(180);
}
void armStop()
{
finderServo.write(90);
}
void armReturn()
{
while(stopButtonValue == 0)
{
stopButtonValue = digitalRead(stopButton);
armIn();
}
armStop();
Serial.print("StopButton Value =");
Serial.println(stopButtonValue);
}
void setup() {
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);
finderServo.attach(9);
pinMode (resetButton, INPUT);
pinMode (stopButton, INPUT);
}
void loop()
{
while(resetButtonValue == 0)
{
resetButtonValue = digitalRead(resetButton);
armStop();
Serial.print("ResetButton Value = ");
Serial.println(resetButtonValue);
delay(50);
}
while (stopButtonValue == 0)
{
stopButtonValue == digitalRead(stopButton);
armReturn();
Serial.print("ResetButton Value = ");
Serial.println(resetButtonValue);
delay(50);
}
encoderRead();
if(encoder0Pos < 150)
{
armOut();
}
if(encoder0Pos > 150)
{
armStop();
}
}
int val;
int encoder0PinA = 12;
int encoder0PinB = 13;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = LOW;
Servo finderServo;
int stopButton = 4;
int resetButton = 3;
int stopButtonValue = 0;
int resetButtonValue = 0;
int encoderRead()
{
n = digitalRead(encoder0PinA);
if ((encoder0PinALast == LOW) && (n == HIGH)) {
if (digitalRead(encoder0PinB) == LOW) {
encoder0Pos--;
} else {
encoder0Pos++;
}
Serial.println (encoder0Pos);
}
encoder0PinALast = n;
}
void armIn()
{
finderServo.write(0);
}
void armOut()
{
finderServo.write(180);
}
void armStop()
{
finderServo.write(90);
}
void armReturn()
{
while(stopButtonValue == 0)
{
stopButtonValue = digitalRead(stopButton);
armIn();
}
armStop();
Serial.print("StopButton Value =");
Serial.println(stopButtonValue);
}
void setup() {
pinMode (encoder0PinA,INPUT);
pinMode (encoder0PinB,INPUT);
Serial.begin (9600);
finderServo.attach(9);
pinMode (resetButton, INPUT);
pinMode (stopButton, INPUT);
}
void loop()
{
while(resetButtonValue == 0)
{
resetButtonValue = digitalRead(resetButton);
armStop();
Serial.print("ResetButton Value = ");
Serial.println(resetButtonValue);
delay(50);
}
while (stopButtonValue == 0)
{
stopButtonValue == digitalRead(stopButton);
armReturn();
Serial.print("ResetButton Value = ");
Serial.println(resetButtonValue);
delay(50);
}
encoderRead();
if(encoder0Pos < 150)
{
armOut();
}
if(encoder0Pos > 150)
{
armStop();
}
}
Issues:
No significant issues have come about other than a minor encoder issue with getting it to read properly but this was resolved.
No comments:
Post a Comment