0% found this document useful (0 votes)
107 views34 pages

Xy Plotter

This document is a project report for a 2D drawing machine created by a group of students at Bangladesh University of Engineering and Technology. It describes the design and development of the machine, which uses a rack and pinion system powered by DC motors to control the placement of a pen and draw on a surface. The machine is able to draw various geometric shapes and could potentially be useful for engineering drawings, reports, and education. The project aims to create a simple, accurate drawing machine to replace manual drawing in certain applications.

Uploaded by

alfredo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views34 pages

Xy Plotter

This document is a project report for a 2D drawing machine created by a group of students at Bangladesh University of Engineering and Technology. It describes the design and development of the machine, which uses a rack and pinion system powered by DC motors to control the placement of a pen and draw on a surface. The machine is able to draw various geometric shapes and could potentially be useful for engineering drawings, reports, and education. The project aims to create a simple, accurate drawing machine to replace manual drawing in certain applications.

Uploaded by

alfredo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTMENT OF MECHANICAL ENGINEERING

BANGLADESH UNIVERSITY OF ENGINEERING AND TECHNOLOGY,


DHAKA-1000,BANGLADESH

2D DRAWING MACHINE
PROJECT REPORT

INSTRUMENTATION AND MEASUREMENT SESSIONAL


(ME 362)

SUBMITTED BY

SHAFKAT AHMED (1010062)

MD. TAFSIR HOSSAIN VHUIYAN (1010070)


MD. MASUDUR RAHMAN (1001078)
MD. SYAM HASAN (1001087)

GROUP NO- B12

SUPERVISED BY

AMINUL ISLAM KHAN, LECTURER


KAZI ARAFAT RAHMAN, LECTURER
KM RAFIDH HASSAN, LECTURER
All rights reserved by Bangladesh university of Engineering and technology (BUET), Dhaka-
1000, Bangladesh . BUET can use and reproduce fully or partially the work being presented
if needed.
ACKNOWLEDGEMENT

`
At the first we would like to be grateful to Allah by whose mercy we complete our project
successfully. It is really an exciting project and for the first time we were given the chance of
creative work under academic course. In this particular project we received kind guideline
and help of many persons. We would like to express humble respect to our parents as their
inspiration and blessing were always with us. Then we want to express our special gratitude
to our respective teacher Abdur Rashid Sarkar.We also like to thank our honorable teachers
Aminul Islam Khan, Kazi Arafat Rahman, KM Rafidh Hassan for their instructive
suggestions and guidelines. Without their proper guideline it would be impossible for us to
complete the project.

ABSTRACT
The project we have worked on is Automatic Drawing Machine. It is very handy in real life
problem facing. Perhaps you have never been gifted at drawing, or you don’t have the time to
do it yourself, so why not let a simple Automatic Drawing Machine draw it for you. This
simple two axis device can accurately moves a pen according to the instruction given to it to
draw out anything.

It has a two axis control and a special mechanism to raise and lower the pen. We have used
rack and pinion system to control the placement of the pen to draw on the paper. It can draw
not only on paper but also on any plane surface placed horizontally below the particular
position of the drawing machine. Each pinion is powered using a single DC motor and it
moves along the rack. The intersection point of the two shafts protude from the motor holder
holds the pen holder. Another rack and pinion system and a small dc motor is used to control
the vertical movement of the Pen above the writing plane. For precession in drawing we also
used pully mechanism.

In our project we only concentrated on drawing geometric shape. If we will have given
enough scope to work on it we can make further improvement like free sketching,
engineering structure drawing and so so.

TABLE OF CONTENTS
CAPTER NO. CHAPTER NAME PAGE NUMBER
1 INTRODUCTION 01
2 METHODOLOGY
3 PROBLEMS& LIMITATION
4 CONCLUSION&
RECOMENDATION
5 REFERENCE

6 APPENDICES

CHAPTER 1

INTRODUCTION

1.1 BACKGROUND
Drawing is a very important aspect in our daily life. It is a part and parcel of education
system. We can not even think of a single day without drawing in study. It is also a very
essential part of any engineering structure design. Again in official affairs we have to perform
certain drawings. Sometimes manual approach to any drawing may be time consuming and
errors may occur. In this case Automatic Drawing Machine can serve the following purposes
with maximum accuracy. It also performs swiftly and smoothly which save our time and
effort.

1.2 STATEMENT OF PROBLEMS


Our project is under the academic course ME 362. We were given the oportunity of choosing
any project according to our will and we chose this very project. We had to complete this
project alongside our academic study. So we could not give our maximum effort to our
project and we had to face certain problems. We had very limited time to finish this project
and we faced difficulties to collect and assemble our desired and required machine parts.

1.2 APPLICATIONS

Our project 2D Drawing Machine is very useful in educational and official works .Because
we can’t think of a single day without drawing anything. Our main purpose of this project is
to make a simple and feasible machine which can draw such things that we draw frequently
in our everyday life. The main applications of our project are given below-
 We are engineering students. So we have to draw a lot of things. Our machine
will help us to draw simple geometric shape, best fitted curve, graphs and
many other 2D shapes.
 In structural and mechanical design accuracy is obvious. Sometimes it
becomes quite difficult to draw exactly and precisely by hand. In such case our
machine can help to draw the structure and machine part accurately and
quickly with minimum percentage of deviation.
 In official affairs, the monthly and annual reports have to be presented in
graphical form. Sometimes they need the best fitted curve. In such case our
drawing machine can help to a great extent.

CHAPTER 2

METHODOLOGY

2.1 Project Design


The entire design can be described by dividing into two subcategories.
1. Mechanical Design
2. Electrical Design

2.1.1 Mechanical Design


The mechanical design of the 2D curve drawing machine is the most important as it
involves higher accuracy in designing different parts for the successful running of the
machine. The mechanical design is developed in “SolidWorks2013” software. The entire
assembly of the machine consists of the following sub assemblies or sections.
1. Pen holder Sub assembly.
2. Motor holder sub assembly.
3. Slider sub assembly.
4. Wooden frame.
5. Rack and pinion system .
6. Pulley mechanism.(In the real view)
Rack and Pinion system
Wooden frame
Motor holder sub assembly

Slider sub assembly


Pen holder sub assembly

Figure 2-1 Solidworks Assembly of the entire structure


Pulley Mechanism

Figure 2-2 Real view of the Entire structure

The Solidworks drawing (2D+3D) of different parts has given below.

1 2 3

4 5

Figure 2-1 Rack and pinion system(All dimension are in millimeter)

(1) Rack (Module-1.25, Pitch height-25, Pressure Angle-20 degree, Face width-5mm);
(2) Pinion for x axis and y axis movement controlling motor ( Module-1.25, Number of
teeth-12, Pressure Angle-20 degree, Face width-5mm);
(3) Pinion of motor for controlling vertical movement of pen (Module-1.25, Number of
teeth-12, Pressure Angle-20 degree, Face width-5mm);
(4) 3D drawing of pinion.
(5) 3D drawing of Rack And pinion system
Figure 2-2a 2D drawing of Different parts of Penholder(All dimensions are in millimeter)
Figure 2-2b 2D drawing of Different parts of Penholder(All dimensions are in millimeter)

Figure 2-3 Solidworks Design of a part which was collected from CD-Drive

Figure 2-4 Pen holder Assembly (Real & Solidworks Assembly)


Figure 2-5a 2D drawing of different parts of motor holder (All dimension are in
millimeter)
Figure 2-5b 2D drawing of different parts of motor holder (All dimension are in
millimeter)
Figure 2-6 3D drawing of Motor holder sub assembly

Figure 2-7 2D drawing of different parts of slider sub assembly(All dimension are in
millimeter)
Figure 2-8 3D drawing of Slider sub assembly

Pulley

Figure 2-9 Pulley mechanism used in the machine

2.1.1.1 Material

The material that is used to made different parts is “Acrylic”. Different parts of the project
has been cut from an Acrylic sheet of 5mm thickness using a leaser cutting machine.

2.1 ELECTRICAL DESIGN

The electric design consists of the following components:


(1)Atmega32 Microcontroller(2 )
(2)L2983 Motor driver IC (2 Piece)
(3)L293D Motor driver IC (1 Piece)
(4) 7805 IC
(5) 7812 IC
(6)20*4 LCD display
(7) Crystal (16Mhz)
(8) Capacitors(100nF)
(9) Wires
(10) Heat sink
(11) Diodes(1N4148,1N4007)
(12) Push switch
(13) Led
(14) Bread board
(15) Vero board
(16) DC geared Motor

Two motor driver IC (L298) is used to control motors which control x axis
and y axis movement. Another motor driver IC (L393D) is used to control
the motor which control the vertical movement of the pen .One
microcontroller control x axis movement controlling motor and the LCD
display .Another microcontroller control y axis movement controlling
motor And pen movement controlling motor.

Circuit diagram of different section of the full diagram has given in the
following page.

Figure 2-10 Keypad circuit diagram


Figure 2-11 LCD Display connections

Figure 2-12 Motor Driver IC connections


Figure 2-13 Full circuit diagram

Figure 2-14 Real view of full circuit diagram

3. WORKING PRICIPLE
When a object move along a curve path with constant velocity than x and y component of the
velocity varies with time .If we consider parametric or polar equation of the curve than it can
be said that the velocity components varies with the angle theta.And the angle theta varies
with time.

=vX

=vy
Again
So if the x and y component of velocity(Vx and Vy) of a object moving at a constant
velocity can be controlled according a specific polar equation of path than the object must
travel along that path.

By using PWM( pulse width modulation ) rotational speed of a motor can be controlled with
higher accuracy. On the other hand the linear speed is proportional to the rotational speed
(v=wr).

In PWM applied voltage to a motor is controlled by a higher frequency signal by controlling


the width of the signal .To control the width of the signal value of a resister called output
compare resister (OCR1A or OCR1B) is controlled with time using a loop according to a
desired equation in the programming .As a result the x and y component of velocity of the
motor is changed with time and the pen moves along that curved path.

PWM (pulse width modulation)

A Pulse Width Modulated signal is a type of digital waveform. It alternates between bursts of
‘On’ and ‘Off’, also known as high and low respectively, at a fixed frequency. The PWM
signal differs from other digital signals (e.g. square waves) because the time that the signal is
high and low can be varied. This is useful because when the PWM signal is averaged with a
simple analogue filter, a DC voltage is produced that is proportional to the duty cycle (which
is the percentage of time that the PWM signal is high). Since a vibration motor's speed and
frequency of vibration is directly proportional to the voltage applied to the motor, we can use
PWM to control precisely how the motor runs.

The PWM signal has three separate components:

 A Voltage, - the value of the ‘on’ or high voltage level (typically between 2 ~ 5V
if PWM signal is produced by a microcontroller / CMOS logic).
 A Frequency - the period of one clock cycle, i.e. one high pulse and one low pulse.
 A Duty Cycle - the ratio of the on-time to the off-time, which controls the resulting
voltage, explained in detail below.

The Duty Cycle represents the length of the On pulse compared to one period cycle. It is
expressed as a percentage. To illustrate the difference in Duty Cycles, there are example
waveforms below:

The resulting voltage, which is seen by the motor, is the average voltage over
the period. It is easily calculated using the following formula:

We can see from the formula that the we can adjust the voltage by changing the
Duty Cycle. For example, if we have a 3 V PWM signal with a 50% Duty
Cycle, the average output voltage is:

If we wanted to increase the voltage to 2.25V we can rearrange the formula to


find the appropriate Duty Cycle
This means that controlling the speed of the motor, the vibration frequency and
also the vibration strength, can easily be achieved by altering the PWM signal’s
Duty Cycle in the microcontroller. The advantage of this technique is that the
microcontroller can make a simple adjustment to it’s output depending upon the
input conditions and its programme. Also certain events., specific output
waveforms can be stored in libraries or memory which can be recalled for

A Real-life Example

Consider the simple waveform below:

Figure PWM Example Waveform

Here we have a simple waveform which starts with a Duty Cycle of 25%, then
increasing to 50%, and finally 75%. Note again that the maximum voltage and
frequency have remained constant, and only the Duty Cycle has changed. We
can calculate the average voltage over each section:

 25% ::
 50% ::
 75% ::
The output voltage, which is the voltage seen by the motor, of the above
waveform is shown below:

Figure Output Voltage of Different Duty Cycles

Please note this is an example aimed at demonstrating the effect of change in


the output voltage with differing the Duty Cycles and that the actual
performance may differ. For instance the acceleration between voltage levels
can differ depending on available current and other circuit components.

Driving Motors with PWM

As demonstrated above, a microcontroller can easily change the voltage applied


to a motor using a PWM signal. It can build quite complex waveform to
increase haptic feedback performance, and even store these waveforms in
libraries or some remote memory location.

Unfortunately, it is not possible to drive the motor directly from the


microcontroller itself due to the current draw of the motor. Hence a switching
amplifier is needed which with appropriate PWM signals to tackle two issues:

 Supplying enough current to drive the motor.


 Supplying enough voltage to meet the required motor start voltage.
Microcontrollers are usually designed to be as efficient as possible with fast
switching capabilities. As a result they use low voltage and low current signals
for their inputs and outputs. Vibration motors, as with most DC motors, have a
maximum operating current much higher than the microcontroller can
provide.In addition, ignoring the current supply problem, the DC output voltage
from the microcontroller may also be too small.Due to this reasons Motor driver
ICs are used. Motor drive chips have multiple benefits. They can have built in
H-bridges for advanced driving techniques, help with voltage regulation, and
often accept PWM signals as control.
LIMITATIONS

Our 2D Drawing Machine is very helpful in our life. But it has some limitations,
because we faced some difficulties during making this machine. So we couldn’t
make it according to our desire. The main limitations are given below-
 Our drawing machine can draw only 2D
drawings. It can’t draw any kind of 3D drawings,
it is the main limitations.
 It can draw only some specific geometrical
shapes depending on the computer program.
We can’t draw anything according to our wish.
 We don’t use computer interfacing in our
project. If that was used our program will
become capable and more feasible to draw any
shapes.
 It can draw only on a horizontal plane, if we
want to draw anything in a vertical or a inclined
plane , we don’t use this machine.
RECOMMENDATIONS

Our 2D Drawing Machine has a number of applications. But it also has some
limitations. So, further improvements of our project are recommended. The
main sectors of improvements are given below-
 We use rack and pinion system only in two sides and
on other two sides we use slider. So it became quite
difficult for us to maintain the horizontal balance
between the motors and the sliders. So if rack and
pinion system is used on four sides, the balance will
be perfect and the percentage of accuracy will be
high.
 We use a small rack and pinion system to control the
vertical movements of the pen. If servo motor is used
the movements will be controlled more precisely.
 If we improve our computer program then the
machine can draw different more shapes according to
our wish.
 Computer interfacing should be included in the
project. Then the machine will be used in more
sectors and it will draw easily different shapes.
CONCLUSIONS
The 2D Drawing machine is very helpful and essential in our everyday life. But we can’t
fulfill our requirement that was given to us . Our machine can draw different straight
geometrical shapes like straight line, triangle ,rectangle etc. but it face some problems to
draw the curves. In computer simulations it doesn’t show any difficulties but when it starts
drawing curves it can’t finish the figure. It may be caused due to connection problems. We
tried our best to solve these problems, but due to time limitations it was difficult for us to find
out the problems. If we have given little more time, then our machine will give better
performance. We hope that after correcting these problems our 2D Drawing Machine will be
a useful and essential machine for our daily life.

CHAPTER 5

REFERENCE

 Mechanical Measurement By Thomas G. Beckwith


Sixth Edition (Pearson Publicatons)
 The Arts of Electronics By Paul Horrowitz
(Megrawill)
 Introduction to Mechatronics and Measurements
systems By Macheal B Histand (Third edition)
 Experimental Methods For Engineers By J.P. Holman
(TATA Megrawill)
 http://en.wikipedia.org/wiki/Simple_Sensor_Interfac
e_protocol
 http://www.instructables.com
 http://www.precisionmicrodrives.com/application-notes-
technical-guides/application-bulletins/ab- 012-driving-
vibration-motors-with-pwm
CHAPTER 6

APPENDICES

6.1 COST ANALYSIS

6.1.1 MECHANICAL PART COST

No. of Element MATERIAL COST(BDT)

1 Acrylic sheet 600


2 Cutting Cost 1400
3 Stainless steel Rod 150
4 Small pulley 120
5 Wood frame 1200
6 Miscellaneous 200
Total 3670
6.1.2 ELECTRICAL PARTS COST

No. of Element MATERIAL AMOUNT COST(BDT)

1 DC motors of 7kg torque 2 900


2 DC motor of 3kg torque 1 350
3 Microcontrollers(AT mega 32) 2 500
4 L298 IC 2 300
5 L293D IC 1 90
6 Heat sink 2 10
8 Bread Board 2 250
10 Vero board 1 20
11 LCD display 1 350
12 Crystal 2 50
13 Switch 14 30
14 7805 IC 1 15
15 7812 IC 1 20
16 Wires 25 feet 150
17 Capacitor 8 10
18 Diode 30 60
Total 3105

Total Cost=6775 (BDT)


6.2 Programming
C code of the machine has given below:
Code for Microcontroller-1:
#include<stdio.h>
#include<avr/io.h>
#include"lcd.h"
#include<util/delay.h>
#include<math.h>
#include<avr/interrupt.h>
#define pi 3.14592654
void Drawing_line(void);
void Drawing_circle(void);
void Drawing_ellipse(void);
void Drawing_quadrilateral(void);
int input_number(unsigned int);
void input_point(unsigned int *p);
void input_length(unsigned int *L);
void init_timer1(void);
unsigned int power_of(unsigned int B, unsigned int E);
unsigned int digits_of_number(int);
unsigned int reset=0,n=0,digits[6]={0,0,0,0,0,0};
float ocr_factor;
int last_value_of_x=0;
char line[16],line1[16];
void main(void)
{
DDRD=0xFF;
unsigned int d;
DDRA=0x00;

if(n==0)
{LCDInit();
n=1;
}
LCDSendCmd(0x01);
LCDGotoXY(1,1);
sprintf(line,"line-1,Quadrilat-2");
LCDString(line);
LCDGotoXY(1,2);
sprintf(line,"Circal-3,ellipse-4");
LCDString(line);
while(1)
{
d=((~(PINA))&0xF);
if(d>0)
{
d=((~(PINA))&0xF)-1;
if(reset==0)
{
if(d==1)
{
_delay_ms(300);
Drawing_line();
}
if(d==2)
{
_delay_ms(300);
Drawing_quadrilateral();
}
else if(d==3)
{
_delay_ms(300);
Drawing_circle();
}
else if(d==4)
{
_delay_ms(300);
Drawing_ellipse();
}
}
else if(d==12)

{
_delay_ms(300);
reset=0;
main();
}
}
}
}

void Drawing_quadrilateral(void)
{
unsigned int length,width,i=0,c;
float t1,t2;
sprintf(line,"Length=?");
input_length(&length);
sprintf(line,"Width=?");
input_length(&width);
LCDSendCmd(0x01);
LCDGotoXY(1,1);
sprintf(line,"Length=%d",length);
LCDString(line);
LCDGotoXY(1,2);
sprintf(line,"Width=%d",width);
LCDString(line);
_delay_ms(145);
while(i<2)
{
t1=(2500*length)/33;
c=t1;
if((t1-c)>.5)
{c=c+1;}
if(i==0)
{
PORTD|=(1<<PD5);
_delay_ms(c);
PORTD&=~(1<<PD5);
t2=(2500*width)/33;
c=t2;
if((t2-c)>.5)
{c=c+1;}
_delay_ms(c+100);}
else
{
PORTD|=(1<<PD4);
_delay_ms(c);
PORTD&=~(1<<PD4);
}
i++;
}
reset=1;

}
int input_number(unsigned int type)
{
int number=0,sign=1;
unsigned int count=1,count1=0,digit[6]={0,0,0,0,0,0},i,d;
while(count<5&&reset==0)
{
d=((~(PINA))&0xF);
if(d>0)
{
d=(~(PINA))&0xF;

if(d<11)
{
digit[count1]=d-1;
LCDDigit(digit[count1]);
count++;
count1++;
LCDGotoXY(count,2);
_delay_ms(300);
}

else if(d==11&&count>1)
{
count=count-1;
if(count1>0)
{count1=count1-1;}
if(sign<0&&count==1)
{
sign*=-1;
}
LCDGotoXY(count,2);
LCDPutchar(' ');
LCDGotoXY(count,2);
_delay_ms(300);

}
else if(d==12)
{
_delay_ms(300);
break;
}
else if(d==13)
{
reset=0;
_delay_ms(100);
main();
}

else if(d==14)
{
if(count==1)
{
sign=-1;
LCDPutchar('-');
count++;
LCDGotoXY(count,2);
}
_delay_ms(300);
}
}
}
for(i=0;i<count1;i++)
{
number+=digit[i]*pow(10,count1-i-1);
}
number=number*sign;
if(((number<-200|number>200)&&type==1)|(number>200&&type==2))
{
LCDSendCmd(0x01);
LCDGotoXY(1,1);
sprintf(line1,"Out of Range");
LCDString(line1);
LCDGotoXY(1,2);
sprintf(line1,"Input Again");
LCDString(line1);
_delay_ms(1500);
LCDSendCmd(0x01);
LCDGotoXY(1,1);
LCDString(line);
LCDGotoXY(1,2);
number=input_number(type);
return number;

}
else if(number<1&&type==2)
{
LCDSendCmd(0x01);
LCDGotoXY(1,1);
if(number==0)
{sprintf(line1,"Invalid");}
else
{sprintf(line1,"-ve Num Invalid");}
LCDString(line1);
LCDGotoXY(1,2);
sprintf(line1,"Input Again");
LCDString(line1);
_delay_ms(1500);
LCDSendCmd(0x01);
LCDGotoXY(1,1);
LCDString(line);
LCDGotoXY(1,2);
number=input_number(type);
}
return numbe
}

unsigned int power_of(unsigned int B, unsigned int E)


{
unsigned int i,value=1;
for(i=0;i<E;i++)
{
value*=B;
}
return value;
}
void input_point(unsigned int *p)
{
unsigned int i=0,j=0;
while(i<2)
{
LCDSendCmd(0x01);
_delay_ms(100);
LCDGotoXY(1,1);

while (i==0&&(line[j])!='_')
{
j++;
}
if(i==0)
{line[j]='x';}
else
{line[j]='y';}
LCDString(line);
LCDGotoXY(1,2);
*p=input_number(1);
if(reset==1)
{break;}
p++;
i++;
}
}
void input_length(unsigned int *L)
{
LCDSendCmd(0x01);
LCDGotoXY(1,1);
LCDString(line);
LCDGotoXY(1,2);
*L=input_number(2);

}
void init_timer1(void)
{
TCCR1A|=(1<<WGM10)|(1<<WGM11)|(1<<WGM12)|(1<<WGM13)|(1<<COM1A1)|(1<<COM1B1);
TCCR1B|=(1<<CS10);
}

Code for microcontroller-2:

#include<stdio.h>
#include<avr/io.h>
#include<util/delay.h>
#define pi 3.14592654
#include<math.h>
void Drawing_line(void);
void Drawing_circle(void);
void Drawing_ellipse(void);
void Drawing_quadrilateral(void);
int input_number(unsigned int);
void input_point(unsigned int *p);
void input_length(unsigned int *L);
unsigned int power_of(unsigned int B, unsigned int E);
unsigned int digits_of_number(int);
unsigned int reset=0,n=0,digits[6]={0,0,0,0,0,0};
int last_value_of_x=0,last_value_of_y=0;
void main(void)
{
DDRD=0xFF;
unsigned int d;
DDRA=0x00;
DDRC=0x0F;
PORTA=0x0F;
_delay_ms(50);
while(1)
{
d=((~(PINA))&0xF);
if(d>0)
{
d=((~(PINA))&0xF)-1;
if(reset==0)
{
if(d==1)
{
_delay_ms(300);
Drawing_line();
}
if(d==2)
{
_delay_ms(300);
Drawing_quadrilateral();
}
else if(d==3)
{
_delay_ms(300);
Drawing_circle();
}
else if(d==4)
{
_delay_ms(300);
Drawing_ellipse();
}
}
else if(d==12)
{
_delay_ms(300);
reset=0;
main();
}
{
}
}
void Drawing_quadrilateral(void)
{
unsigned int length,width,i=0,c;
float t1,t2;
input_length(&length);
input_length(&width);
_delay_ms(5);
PORTC|=(1<<PC1);
_delay_ms(135);
PORTC&=~(1<<PC1);

t2=(2500*length)/33;
c=t2;
if((t2-c)>.5)
{c=c+1;}
_delay_ms(c+100);
while(i<2)
{
t1=(2500*width)/33;
c=t1;
if((t1-c)>.5)
{c=c+1;}
if(i==0)
{
PORTD|=(1<<PD5);
_delay_ms(c);
PORTD&=~(1<<PD5);
t2=(2500*length)/33;
c=t2;
if((t2-c)>.5)
{c=c+1;}
_delay_ms(c+100);
}
else
{
PORTD|=(1<<PD4);
_delay_ms(c);
PORTD&=~(1<<PD4);
}
i++;
}

PORTC|=(1<<PC2);
_delay_ms(135);
PORTC&=~(1<<PC2);
reset=1;

int input_number(unsigned int type)


{
int number=0,sign=1;
unsigned int count=0,digit[6]={0,0,0,0,0,0},i,d;
while(count<5&&reset==0)
{
d=((~(PINA))&0xF);
if(d>0)
{
d=(~(PINA))&0xF;

if(d<11)
{
digit[count]=d-1;
count++;
_delay_ms(300);
}

else if(d==11&&count>1)
{
if(count>0)
{count=count-1;}

if(sign<0&&count==0)
{
sign*=-1;
}
_delay_ms(300);

}
else if(d==12)
{
_delay_ms(300);
break;
}
else if(d==13)
{
reset=0;
_delay_ms(100);
main();
}

else if(d==14)
{
if(count==0)
{
sign=-1;

}
_delay_ms(302);
}
}
}

for(i=0;i<count;i++)
{
number+=digit[i]*pow(10,count-i-1);
}
number=number*sign;
if(((number<-200|number>200)&&type==1)|(number>200&&type==2))
{
_delay_ms(1500);

number=input_number(type);
return number;

}
else if(number<1&&type==2)
{
_delay_ms(1500);
number=input_number(type);
}
return number;
}
unsigned int power_of(unsigned int B, unsigned int E)
{
unsigned int i,value=1;
for(i=0;i<E;i++)
{
value*=B;
}
return value;
}
void input_point(unsigned int *p)
{unsigned int i=0;
while(i<2)
{
_delay_ms(112);
*p=input_number(1);
if(reset==1)
{break;}
p++;
i++;
}
}

void input_length(unsigned int *L)


{
_delay_ms(5);
*L=input_number(2);

void init_timer1(void)
{
TCCR1A|=(1<<WGM10)|(1<<WGM11)|(1<<WGM12)|(1<<WGM13)|(1<<COM1A1)|(1<<COM1B1);
TCCR1B|=(1<<CS10);}

You might also like