Commit 7920039e by satsob

LCD Robot Update

parent 9327e4dc
Showing with 70 additions and 71 deletions
......@@ -4,7 +4,7 @@
LiquidCrystal_I2C lcd(0x3F, 16, 2); // Address found using lcd scanner, columns, rows
/*
Test.
TEST!
There are 16x2 segments on the LCD display. Each segment is 8x5 (width x length).
The points in the segment starts from left to right and from top to bottom.
......@@ -12,39 +12,36 @@ LiquidCrystal_I2C lcd(0x3F, 16, 2); // Address found using lcd scanner, columns,
For example, 00010 means that in the first line only the forth box in segment is filled.
Other boxes in the line are unfilled (not active).
*/
//byte test[8] = {B00001, B00010, B00100, B01000, B10000, B00101, B00110, B00111};
// Intialize for robot driving
/* Byte array to store the values for LCD. B or 0b. Equals one segment.*/
/*
Intialize for robot driving pathway.
Byte array to store the values for LCD. B or 0b. Equals one segment.
*/
byte liigun[8] = {B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000};
byte temp[8] = {0};
bool sameArray = false;
int sameCounter = 0;
byte temp[8] = {0}; // To temporarily store liigun array
bool sameArray = false; // To check whether to save temp array or not
int sameCounter = 0; // To check whether to save temp array or not. 1 - Store array
// 2 - Store it back to liigun array and reset the counter
/* LCD coordinates. To create points on LCD screen segments. */
int pointx = 0; // Can only be 0 or 1; sets x position on lcd
int pointy = 0; // Can be max 7; sets y postion on lcd
int rowCounter = 0; // Can be max 8
int colCounter = 0; // Can be max 5
/* To store the values for moving on LCD screen. To move in array. */
//int countera = 0 // Initialize countera as array[countera][]
int counterb = 7 // Initialize counterb as array[][counterb]. 7 to start from the bottom
int cursorCounter = 0; // Initialize cursorCounter that sets cursor point on lcd
int counterb = 7 // Initialize counterb as array[counterb]. 7 to start from the bottom, 0 from top.
int cursorCounter = 0; // Initialize cursorCounter that sets cursor point on LCD
int pos = 4; // Initialize pos (position) to calculate the correct postion
int posx = 0; // Starting x position and the position of x-axis segment, max 79
int posy = 8; // Starting y position and the position of y-axis segment, max 15
/* To detect whether we have moved to another segment on display or not. */
//bool posChange = false; // To change positions or not to change
//int movex = 0; // Moving and detecting x-coordinates
//int movey = 0; // Moving and detecting y-coordinates
/*
* Robot movement stuff!
*/
Robot movement stuff!
*/
/* Define */
/* Defines */
#define rightServo 5 // Define Servo right pin
#define leftServo 6 // Define Servo left pin
......@@ -52,24 +49,24 @@ int posy = 8; // Starting y position and the position of y-axis segmen
Servo rightWheel;
Servo leftWheel;
/* Define functions used for the robot to control */
/* Define functions used to control the robot. */
/* Stop the robot */
void setWheelsStop() {
rightWheel.writeMicroseconds(1500);
leftWheel.writeMicroseconds(1500);
}
/* Drive forward */
void setWheelsForward(){
void setWheelsForward() {
rightWheel.write(1300);
leftWheel.write(1700);
}
/* Drive right */
void setWheelsRight(){
void setWheelsRight() {
rightWheel.write(1700);
leftWheel.write(1700);
}
/* Drive left */
void setWheelsLeft(){
void setWheelsLeft() {
rightWheel.write(1300);
leftWheel.write(1300);
}
......@@ -82,11 +79,11 @@ void setup()
/* Attach servos to digital pins defined earlier */
rightWheel.attach(rightServo);
leftWheel.attach(leftServo);
/* Put servos to standstill */
//setWheelsStop();
/* Ignore the commented out code! These are for testing purposes! */
/***** Ignore the commented out code! These are FOR TESTING purposes! *****/
// lcd.backlight();
// lcd.clear();
......@@ -106,85 +103,80 @@ void setup()
// lcd.setCursor(0, 0);
// lcd.write(6);
/* Testing bit shifting and printing on serial monitor! */
// unsigned int ex = 0b00100; // Initialize unsigned int
// Serial.println(ex); // Prints decimal number
// ex = ex << 1; // Bitwise operation -> shifting to left one time
// Serial.println(ex, BIN); // Prints binary number
/***** Ignore the commented out code! These are FOR TESTING purposes! *****/
}
void loop()
{
/* Check if you can move forward. YOU CAN ONLY MOVE FORWARD EIGHTY (80) TIMES! */
if (posx >= 79) {
Serial.println("ERROR!");
exit(0);
}
if (otse) {
// Check if you can move forward. You CAN ONLY move forward eighty (80) times.
if (colCounter == 79) {
Serial.println("ERROR!");
exit(0);
}
// Check in which segment you are going to draw a point.
/* Check in which segment you are going to draw a point. */
if (posx % 5 == 0) {
changeSegment(2); // Two to move forward
}
// DO NOT CHANGE counterb HERE! Change only when moving right or left!
/* DO NOT CHANGE counterb HERE! Change only when moving right or left! */
liigun[counterb] = liigun[counterb] | (1 << pos);
lcd.createChar(cursorCounter, liigun[counterb]);
lcd.setCursor(pointx, pointy);
lcd.write(cursorCounter);
colCounter++; // Increment colCounter on keep count on which column we're at.
posx++; // Increment posx to move on the segment to know were we at.
pos--; // Decrement pos to get the correct power of 2 to add to counterb.
}
else if (parem) {
// Check in which segment you are going to draw a point.
/* Check if you can move right. */
if (pointy == 1 && posy == 0) {
Serial.println("ERROR! CANNOT MOVE RIGHT NO MORE!");
exit(0);
}
/* Check in which segment you are going to draw a point. */
if (posy == 8) {
changeSegment(1); // One to move down (right)
} else {
counterb++; // Increment counterb to "move right" in array.
counterb++; // Increment counterb to "move right" in array.
}
// Check if you can move right.
/*if (counterb == 7) {
Serial.println("ERROR!");
exit(0);
}*/
liigun[counterb] = liigun[counterb] | (1 << pos);
lcd.createChar(cursorCounter, liigun[counterb]);
lcd.setCursor(pointx, pointy);
lcd.write(cursorCounter);
colCounter++; // Increment colCounter on keep count on which column we're at.
posx++; // Increment posx to move forward one step.
posy--; // Decrement posy to move down one step.
pos--; // Decrement pos to get the correct power of 2 to add to counterb.
}
else if (vasak) {
// Check in which segment you are going to draw a point.
/* Check if you can move left. */
if (pointy == 0 && posy == 15) {
Serial.println("ERROR! CANNOT MOVE LEFT NO MORE!");
exit(0);
}
/* Check in which segment you are going to draw a point. */
if (posy == 7) {
changeSegment(0); // Zero to move up (left)
} else {
counterb--; // Decrement counterb to "move left" in array.
counterb--; // Decrement counterb to "move left" in array.
}
// Check if you can move left.
/*if (counterb == 0) {
Serial.println("ERROR!");
exit(0);
}*/
liigun[counterb] = liigun[counterb] | (1 << pos);
lcd.createChar(cursorCounter, liigun[counterb]);
lcd.setCursor(pointx, pointy);
lcd.write(cursorCounter);
colCounter++; // Increment colCounter on keep count on which column we're at.
posx++; // Increment posx to move forward one step.
posy++; // Increment posy to move up one step.
pos--; // Decrement pos to get the correct power of 2 to add to counterb.
......@@ -193,10 +185,18 @@ void loop()
void changeSegment(int a) {
/*if (pos < 4)
byte temp[] = liigun; // Save for when you need the old array back*/
// Move down if a == 1, else move up if a == 0 or forward if a == 2
/*
Here it is determined whether to increment or decrement the position on the LCD.
For moving forward a is 2, right a is 1 and left a is 0.
According to the int value it's determined whether to increment pointx or pointy.
Boolean sameArray and int sameCounter is used when we change the segment, but later
we need the old array back if we return to the previous segment so that
the path is not lost. If the counter is two then we restore the previous array.
cursorCounter is used to know in which segment to create the pathway.
*/
if (a == 2) {
pointx++;
pos = 4; // Reinitialize pos to 4.
......@@ -236,31 +236,30 @@ void changeSegment(int a) {
counterb = 7;
}
// Increment cursorCounter for next segment.
//cursorCounter++;
if (sameArray) {
if (sameCounter == 1) {
// Copy the contents of array liigun to array temp for later use.
/* Copy the contents of array liigun to array temp for later use. */
memcpy(temp, liigun, sizeof(liigun)); // OR sizeof(temp)
//resetArray();
// Increment cursorCounter for next segment.
/* Increment cursorCounter for next segment. */
cursorCounter++;
}
else if (sameCounter == 2) { // If you need to copy the contents of temp back to array.
memcpy(liigun, temp, sizeof(temp)); // OR sizeof(temp)
memset(temp,0,sizeof(temp)); // Empty temp array
memset(temp, 0, sizeof(temp)); // Empty temp array
cursorCounter--;
sameCounter = 0;
sameArray = false;
}
} else {
//resetArray();
// Increment cursorCounter for next segment.
/* Increment cursorCounter for next segment. */
cursorCounter++;
}
}
/***** WORK IN PROGRESS *****/
//void resetArray() {
// // Reinitizialize robotMoving 2D array.
// memset(robotMoving,0,sizeof(robotMoving));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment