The mechanical part is nearly done except for one part. I am a few parts short of making the arm that will be used to cut the tree. I will mount it on the other side of the claw where I have room. I was able to put the Sabertooth and battery underneath the top platform to free up some space and conceal some of the wiring. I put the Sabertooth and LCD screen into TX ports like I did before and the servos and IR sensors to PWM ports. Everything turns on so I just need to complete the programming part to bring it all together.
For the programming, I am trying to work in a linear fashion instead of jumping around from line to line. This makes it much easier to follow and write as I progress through this. I have the beginning part programmed so far. I am still working on the setup for the sensors but once I have that it will hopefully go smoothly.
/*
TX
3 LCD screen
2 Speed controller
PWM
11 IR remote
10 SHARP Positional Servo
9 SHARP IR
8 CLAW Postitional Vex
7 Arm Positional Servo
6 Saw Continuous
*/
#include <IRremote.h> //library needed for the ir sensor and remote
#include <Servo.h>
byte clrscn = 12; //variable to clear the LCD screen
int tree = 0; //number of trees to be cut
long int remote = 0; //value received from the remote
int RECV_PIN = 11; //sets RECV_PIN to pin 11
IRrecv irrecv(RECV_PIN); //sets the IR sensor to pin 11
decode_results results; //statement to decode the results from the IR sensor
void halt()
{ //function to stop the robot
Serial2.write(0);
delay(500);
}
void forward() //function to make the robot move forward
{
Serial2.write(100);
Serial2.write(228);
delay(500);
}
void backwards() //function to make the robot move backwards
{
Serial2.write(28);
Serial2.write(155);
delay(500);
}
void turnLeft() //function to turn left
{
Serial2.write(100);
Serial2.write(154);
delay(250);
}
void turnRight() //function to turn right
{
Serial2.write(28);
Serial2.write(228);
delay(250);
}
void setup()
{
Serial.begin(9600); //makes the Serial monitor, Sabertooth, and the LCD screen on the same level
Serial2.begin(9600);
Serial3.begin(9600);
irrecv.enableIRIn(); //starts the IR receiver
}
void loop()
{
halt();
Serial3.write(clrscn);
Serial3.print("Enter a");
delay(2000);
Serial3.write(clrscn);
Serial3.print("Number 1-9");
delay(2000);
Serial3.write(clrscn);
while(remote == 0) //enters this loop if the IR sensor detects a signal
{
irrecv.decode(&results);
long int remote = results.value; //puts the signal received by the remote into an integer type long
}
Serial.println(results.value); //prints to the serial monitor to troubleshoot
switch(remote) //switch case structure for the results that the IR sensor receives from the remote
{
case 1 || case 2049: //if 1 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("One");
int tree = 1;
//irrecv.resume(); // Receive the next value
break;
case 2 || case 2050: //if 2 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Two");
int tree = 2;
//irrecv.resume(); // Receive the next value
break;
case 3 || case 2051: //if 3 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Three");
int tree = 3;
//irrecv.resume(); // Receive the next value
break;
case 4 || case 2052: //if 4 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Four");
int tree = 4;
//irrecv.resume(); // Receive the next value
break;
case 5 || case 2053: //if 5 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Five");
int tree = 5;
//irrecv.resume(); // Receive the next value
break;
case 6 || case 2054: //if 6 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Six");
int tree = 6;
//irrecv.resume(); // Receive the next value
break;
case 7 || case 2055: //if 7 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Seven");
int tree = 7;
//irrecv.resume(); // Receive the next value
break;
case 8 || case 2056: //if 8 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Eight");
int tree = 8;
//irrecv.resume(); // Receive the next value
break;
case 9 || case 2057: //if 9 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Nine");
int tree = 9;
//irrecv.resume(); // Receive the next value
break;
default: //if none of the above buttons are pressed
Serial3.write(12);
delay(5);
Serial3.print("Enter a");
delay(2000);
Serial3.print("Number 1-9");
halt();
delay(100);
irrecv.resume(); // Receive the next value
}
/*
rightServo.attach(12); //Sets the right servo to I/O 12
leftServo.attach(13);
*/
}
TX
3 LCD screen
2 Speed controller
PWM
11 IR remote
10 SHARP Positional Servo
9 SHARP IR
8 CLAW Postitional Vex
7 Arm Positional Servo
6 Saw Continuous
*/
#include <IRremote.h> //library needed for the ir sensor and remote
#include <Servo.h>
byte clrscn = 12; //variable to clear the LCD screen
int tree = 0; //number of trees to be cut
long int remote = 0; //value received from the remote
int RECV_PIN = 11; //sets RECV_PIN to pin 11
IRrecv irrecv(RECV_PIN); //sets the IR sensor to pin 11
decode_results results; //statement to decode the results from the IR sensor
void halt()
{ //function to stop the robot
Serial2.write(0);
delay(500);
}
void forward() //function to make the robot move forward
{
Serial2.write(100);
Serial2.write(228);
delay(500);
}
void backwards() //function to make the robot move backwards
{
Serial2.write(28);
Serial2.write(155);
delay(500);
}
void turnLeft() //function to turn left
{
Serial2.write(100);
Serial2.write(154);
delay(250);
}
void turnRight() //function to turn right
{
Serial2.write(28);
Serial2.write(228);
delay(250);
}
void setup()
{
Serial.begin(9600); //makes the Serial monitor, Sabertooth, and the LCD screen on the same level
Serial2.begin(9600);
Serial3.begin(9600);
irrecv.enableIRIn(); //starts the IR receiver
}
void loop()
{
halt();
Serial3.write(clrscn);
Serial3.print("Enter a");
delay(2000);
Serial3.write(clrscn);
Serial3.print("Number 1-9");
delay(2000);
Serial3.write(clrscn);
while(remote == 0) //enters this loop if the IR sensor detects a signal
{
irrecv.decode(&results);
long int remote = results.value; //puts the signal received by the remote into an integer type long
}
Serial.println(results.value); //prints to the serial monitor to troubleshoot
switch(remote) //switch case structure for the results that the IR sensor receives from the remote
{
case 1 || case 2049: //if 1 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("One");
int tree = 1;
//irrecv.resume(); // Receive the next value
break;
case 2 || case 2050: //if 2 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Two");
int tree = 2;
//irrecv.resume(); // Receive the next value
break;
case 3 || case 2051: //if 3 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Three");
int tree = 3;
//irrecv.resume(); // Receive the next value
break;
case 4 || case 2052: //if 4 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Four");
int tree = 4;
//irrecv.resume(); // Receive the next value
break;
case 5 || case 2053: //if 5 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Five");
int tree = 5;
//irrecv.resume(); // Receive the next value
break;
case 6 || case 2054: //if 6 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Six");
int tree = 6;
//irrecv.resume(); // Receive the next value
break;
case 7 || case 2055: //if 7 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Seven");
int tree = 7;
//irrecv.resume(); // Receive the next value
break;
case 8 || case 2056: //if 8 is pressed
Serial3.write(12);
delay(5);
Serial3.print("Eight");
int tree = 8;
//irrecv.resume(); // Receive the next value
break;
case 9 || case 2057: //if 9 is pressed
Serial3.write(12); //clears the screen
delay(5);
Serial3.print("Nine");
int tree = 9;
//irrecv.resume(); // Receive the next value
break;
default: //if none of the above buttons are pressed
Serial3.write(12);
delay(5);
Serial3.print("Enter a");
delay(2000);
Serial3.print("Number 1-9");
halt();
delay(100);
irrecv.resume(); // Receive the next value
}
/*
rightServo.attach(12); //Sets the right servo to I/O 12
leftServo.attach(13);
*/
}
No comments:
Post a Comment