Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
satsob
/
Robotite_ylesannete_projekt
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7920039e
authored
Dec 07, 2020
by
satsob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LCD Robot Update
parent
9327e4dc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
61 deletions
LCD_Draw_Robot_Steps/LCD_16x2_b2.ino
LCD_Draw_Robot_Steps/LCD_16x2_b2.ino
View file @
7920039e
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
LiquidCrystal_I2C
lcd
(
0x3F
,
16
,
2
);
// Address found using lcd scanner, columns, rows
LiquidCrystal_I2C
lcd
(
0x3F
,
16
,
2
);
// Address found using lcd scanner, columns, rows
/*
/*
T
est.
T
EST!
There are 16x2 segments on the LCD display. Each segment is 8x5 (width x length).
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.
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,
...
@@ -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.
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).
Other boxes in the line are unfilled (not active).
*/
*/
//byte test[8] = {B00001, B00010, B00100, B01000, B10000, B00101, B00110, B00111};
//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
liigun
[
8
]
=
{
B00000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
,
B00000
};
byte
temp
[
8
]
=
{
0
};
byte
temp
[
8
]
=
{
0
};
// To temporarily store liigun array
bool
sameArray
=
false
;
bool
sameArray
=
false
;
// To check whether to save temp array or not
int
sameCounter
=
0
;
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. */
/* LCD coordinates. To create points on LCD screen segments. */
int
pointx
=
0
;
// Can only be 0 or 1; sets x position on lcd
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
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. */
/* 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, 0 from top.
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
cursorCounter
=
0
;
// Initialize cursorCounter that sets cursor point on lcd
int
pos
=
4
;
// Initialize pos (position) to calculate the correct postion
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
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
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 */
/* Define
s
*/
#define rightServo 5 // Define Servo right pin
#define rightServo 5 // Define Servo right pin
#define leftServo 6 // Define Servo left 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
...
@@ -52,24 +49,24 @@ int posy = 8; // Starting y position and the position of y-axis segmen
Servo
rightWheel
;
Servo
rightWheel
;
Servo
leftWheel
;
Servo
leftWheel
;
/* Define functions used
for the robot to control
*/
/* Define functions used
to control the robot.
*/
/* Stop the robot */
/* Stop the robot */
void
setWheelsStop
()
{
void
setWheelsStop
()
{
rightWheel
.
writeMicroseconds
(
1500
);
rightWheel
.
writeMicroseconds
(
1500
);
leftWheel
.
writeMicroseconds
(
1500
);
leftWheel
.
writeMicroseconds
(
1500
);
}
}
/* Drive forward */
/* Drive forward */
void
setWheelsForward
(){
void
setWheelsForward
()
{
rightWheel
.
write
(
1300
);
rightWheel
.
write
(
1300
);
leftWheel
.
write
(
1700
);
leftWheel
.
write
(
1700
);
}
}
/* Drive right */
/* Drive right */
void
setWheelsRight
(){
void
setWheelsRight
()
{
rightWheel
.
write
(
1700
);
rightWheel
.
write
(
1700
);
leftWheel
.
write
(
1700
);
leftWheel
.
write
(
1700
);
}
}
/* Drive left */
/* Drive left */
void
setWheelsLeft
(){
void
setWheelsLeft
()
{
rightWheel
.
write
(
1300
);
rightWheel
.
write
(
1300
);
leftWheel
.
write
(
1300
);
leftWheel
.
write
(
1300
);
}
}
...
@@ -86,7 +83,7 @@ void setup()
...
@@ -86,7 +83,7 @@ void setup()
/* Put servos to standstill */
/* Put servos to standstill */
//setWheelsStop();
//setWheelsStop();
/*
Ignore the commented out code! These are for testing purposes!
*/
/*
**** Ignore the commented out code! These are FOR TESTING purposes! ****
*/
// lcd.backlight();
// lcd.backlight();
// lcd.clear();
// lcd.clear();
...
@@ -106,85 +103,80 @@ void setup()
...
@@ -106,85 +103,80 @@ void setup()
// lcd.setCursor(0, 0);
// lcd.setCursor(0, 0);
// lcd.write(6);
// lcd.write(6);
/* Testing bit shifting and printing on serial monitor! */
/***** Ignore the commented out code! These are FOR TESTING purposes! *****/
// 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
}
}
void
loop
()
void
loop
()
{
{
if
(
otse
)
{
/* Check if you can move forward. YOU CAN ONLY MOVE FORWARD EIGHTY (80) TIMES! */
// Check if you can move forward. You CAN ONLY move forward eighty (80) times.
if
(
posx
>=
79
)
{
if
(
colCounter
==
79
)
{
Serial
.
println
(
"ERROR!"
);
Serial
.
println
(
"ERROR!"
);
exit
(
0
);
exit
(
0
);
}
}
// Check in which segment you are going to draw a point.
if
(
otse
)
{
/* Check in which segment you are going to draw a point. */
if
(
posx
%
5
==
0
)
{
if
(
posx
%
5
==
0
)
{
changeSegment
(
2
);
// Two to move forward
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
);
liigun
[
counterb
]
=
liigun
[
counterb
]
|
(
1
<<
pos
);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
write
(
cursorCounter
);
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.
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.
pos
--
;
// Decrement pos to get the correct power of 2 to add to counterb.
}
}
else
if
(
parem
)
{
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
)
{
if
(
posy
==
8
)
{
changeSegment
(
1
);
// One to move down (right)
changeSegment
(
1
);
// One to move down (right)
}
else
{
}
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
);
liigun
[
counterb
]
=
liigun
[
counterb
]
|
(
1
<<
pos
);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
write
(
cursorCounter
);
lcd
.
write
(
cursorCounter
);
colCounter
++
;
// Increment colCounter on keep count on which column we're at.
posx
++
;
// Increment posx to move forward one step.
posx
++
;
// Increment posx to move forward one step.
posy
--
;
// Decrement posy to move down one step.
posy
--
;
// Decrement posy to move down one step.
pos
--
;
// Decrement pos to get the correct power of 2 to add to counterb.
pos
--
;
// Decrement pos to get the correct power of 2 to add to counterb.
}
}
else
if
(
vasak
)
{
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
)
{
if
(
posy
==
7
)
{
changeSegment
(
0
);
// Zero to move up (left)
changeSegment
(
0
);
// Zero to move up (left)
}
else
{
}
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
);
liigun
[
counterb
]
=
liigun
[
counterb
]
|
(
1
<<
pos
);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
createChar
(
cursorCounter
,
liigun
[
counterb
]);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
setCursor
(
pointx
,
pointy
);
lcd
.
write
(
cursorCounter
);
lcd
.
write
(
cursorCounter
);
colCounter
++
;
// Increment colCounter on keep count on which column we're at.
posx
++
;
// Increment posx to move forward one step.
posx
++
;
// Increment posx to move forward one step.
posy
++
;
// Increment posy to move up one step.
posy
++
;
// Increment posy to move up one step.
pos
--
;
// Decrement pos to get the correct power of 2 to add to counterb.
pos
--
;
// Decrement pos to get the correct power of 2 to add to counterb.
...
@@ -193,10 +185,18 @@ void loop()
...
@@ -193,10 +185,18 @@ void loop()
void
changeSegment
(
int
a
)
{
void
changeSegment
(
int
a
)
{
/*if (pos < 4)
/*
byte temp[] = liigun; // Save for when you need the old array back*/
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.
*/
// Move down if a == 1, else move up if a == 0 or forward if a == 2
if
(
a
==
2
)
{
if
(
a
==
2
)
{
pointx
++
;
pointx
++
;
pos
=
4
;
// Reinitialize pos to 4.
pos
=
4
;
// Reinitialize pos to 4.
...
@@ -236,31 +236,30 @@ void changeSegment(int a) {
...
@@ -236,31 +236,30 @@ void changeSegment(int a) {
counterb
=
7
;
counterb
=
7
;
}
}
// Increment cursorCounter for next segment.
//cursorCounter++;
if
(
sameArray
)
{
if
(
sameArray
)
{
if
(
sameCounter
==
1
)
{
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)
memcpy
(
temp
,
liigun
,
sizeof
(
liigun
));
// OR sizeof(temp)
//resetArray();
//resetArray();
/
/ Increment cursorCounter for next segment.
/
* Increment cursorCounter for next segment. */
cursorCounter
++
;
cursorCounter
++
;
}
}
else
if
(
sameCounter
==
2
)
{
// If you need to copy the contents of temp back to array.
else
if
(
sameCounter
==
2
)
{
// If you need to copy the contents of temp back to array.
memcpy
(
liigun
,
temp
,
sizeof
(
temp
));
// OR sizeof(temp)
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
--
;
cursorCounter
--
;
sameCounter
=
0
;
sameCounter
=
0
;
sameArray
=
false
;
sameArray
=
false
;
}
}
}
else
{
}
else
{
//resetArray();
//resetArray();
/
/ Increment cursorCounter for next segment.
/
* Increment cursorCounter for next segment. */
cursorCounter
++
;
cursorCounter
++
;
}
}
}
}
/***** WORK IN PROGRESS *****/
//void resetArray() {
//void resetArray() {
// // Reinitizialize robotMoving 2D array.
// // Reinitizialize robotMoving 2D array.
// memset(robotMoving,0,sizeof(robotMoving));
// memset(robotMoving,0,sizeof(robotMoving));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment