Programming

The control program performs four main functions for the plotter: interpretting and storing the character string, finding the home position, moving to the correct grid position, and writing the individual characters.

Character Storing

Using the two toggles and the sliding potentiometer, an array of characters can be stored in the control program. The potentiometer is connected through an analog input which returns a value of 0-255 while the toggles are connected to digital inputs which return either true or false. The program takes the input of 0-255 and multiplies it by a factor of 28/255 to scale it to 0-28, which can then be mapped to a character. The character selected is displayed on the LCD, as well as the previously stored characters. To select a character, the user moves the first toggle back and forth. On the last character selection, both of the toggles are moved to exit the control loop. Below is the character storing code.

	while(digital(13)){
while(digital(12)){
/*getting the pot value and converting it to a letter */
t=(float) analog(0)*(28.0/255.0);
if(t<=1.0)
l='A';
if(t<=2.0 && t>1.0)
l='B';
. . .
if(t<=26.0 && t>25.0)
l='Z';
if(t<=27.0 && t>26.0)
l=' ';
if(t<=28.0 && t>27.0)
l='.';
/* printing the current string */
for(p=0; p<c; p++)
printf("%c", q[p]);
printf("%c\n", l);
sleep(0.25);
}
/* assigning the new letter */
q[c]=l;
c++;
sleep(1.0);
}

Finding Home

The home position is found by two limit switches on the x and y axes. One motor at a time is advanced backward until the switches return a signal which indicates it has been hit. The global position counters are then set to zero. The go_home() function code is below.

	 void go_home(){
while(digital(15)){
backx();
}
while(digital(14)){
backy();
}
xc=0;
yc=0;
}

Grid Positioning

The grid positioning feature of the program is divided into a section of the main code which operates as a counter as well as a sub-function which goes to an individual gird location. The section of the main code counts the number of characters written and tells the sub-function to move to the appropriate white board location. The subfunction utilizes the global positioning counters to move until it is at the proper location, moving in one direction at a time. It also includes buffers in each direction as well as the general size of the letters so that the characters do not overlap on the white board. The positioning code is below.

	/* writing the characters */	
for(m=0;m<c;++m){
if(x<=MAX_X){
go_here(x,y);
write(q[m]);
x++;
}
else{
x=0;
y++;
go_here(x,y);
write(x[m]);
}
} /*goes to grid position to write letter with buffer in between letters */
void go_here(int x, int y){
if(xc> (x*(LENGTH+X_BUFF))){
while(xc> (x*(LENGTH+X_BUFF))){
backx();
xc=xc-4;
}
}
if(xc< (x*(LENGTH+X_BUFF))){
while(xc<(x*(LENGTH+X_BUFF))){
stepx();
xc=xc+4;
}
}
if(yc> (y*(LENGTH+Y_BUFF))){
while(yc> (y*(LENGTH+Y_BUFF))){
backy();
yc=yc-4;
}
}
if(yc< (y*(LENGTH+Y_BUFF)){
while(yc< (y*(LENGTH+Y_BUFF))){
stepy();
yc=yc+4;
}
}
}

Character Writing

The character writing sub function used an independent position counter which utilized the fact that the pen was already positioned at the lower left corner of the blank grid space. Predefined strokes were written for vertical, horizontal, and varying degrees of slanted lines. Functions were also written to raise and lower the pen by writing and clearing a bit on the digital output. Using these options, each letter defined as certain strokes in the sub-function. Below is part of the writing code.

	void write(char q){						
int xn=0, yn=LENGTH;
if(q=='A'){
pen_down();
while(yn> 0){
byyfx(); yn=yn-4; xn=xn+4;
}
while(yn<LENGTH){
fyyfx(); yn=yn+4; xn=xn+4;
}
pen_up();
while(xn>LENGTH/4){
backx();
xn=xn-4;
}
while(yn>LENGTH/2){
backy();
yn=yn-4;
}
pen_down();
while(xn<(LENGTH/4.0)*3){
stepx();
xn=xn+4;
}
pen_up();
}
. . . xc=xc+xn;
yc=yc+yn-LENGTH;
}