KODUMUZ :
#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7
int xAxis, yAxis;
işaretsiz int x = 0
;
işaretsiz int y = 0
;
int motorSpeedA = 0 ;
int motorSpeedB = 0 ;
geçersiz kurulum ( ) {
pinMode ( ena, ÇIKIŞ
) ;
pinMode ( ENB ÇIKIŞ
) ;
pinMode ( in1,
OUTPUT ) ;
pinMode ( in2,
OUTPUT ) ;
pinMode ( in3, ÇIKIŞ
) ;
pinMode ( in4, ÇIKIŞ
) ;
Seri. başlar ( 38400
) ;
}
boşluk döngüsü ( ) {
X = 510 / 4 ;
Y = 510 / 4 ;
while ( Seri.
kullanılabilir ( ) > = 2 ) {
x = Seri read ( )
;
gecikme ( 10 ) ;
y = Seri read ( )
;
}
gecikme ( 10 ) ;
xAxis = x * 4 ;
yAxis = y * 4 ;
eğer ( yAxis <
470 ) {
digitalWrite (
in1, HIGH ) ;
digitalWrite (
in2, LOW ) ;
digitalWrite ( in3
, YÜKSEK ) ;
digitalWrite (
in4, DÜŞÜK ) ;
motorSpeedA =
harita ( yAxis, 470 , 0 , 0 , 255 ) ;
motorSpeedB =
harita ( yAxis, 470 , 0 , 0 , 255 ) ;
}
aksi takdirde (
yAxis> 550 ) {
digitalWrite (
in1, LOW ) ;
digitalWrite (
in2, HIGH ) ;
digitalWrite ( in3
, DÜŞÜK ) ;
digitalWrite (
in4, YÜKSEK ) ;
motorSpeedA =
harita ( yAxis, 550 , 1023 , 0 , 255 ) ;
motorSpeedB =
harita ( yAxis, 550 , 1023 , 0 , 255 ) ;
}
{
motorSpeedA = 0 ;
motorSpeedB = 0 ;
}
eğer ( xAxis <
470 ) {
int xMapped =
harita ( xAxis, 470 , 0 , 0 , 255 ) ;
motorSpeedA =
motorSpeedA - xMapped;
motorSpeedB =
motorSpeedB + xMapped;
eğer ( motorSpeedA
< 0 ) {
motorSpeedA = 0
;
}
eğer (
motorSpeedB> 255 ) {
motorSpeedB =
255 ;
}
}
eğer ( xAxis> 550
) {
int xMapped =
harita ( xAxis, 550 , 1023 , 0 , 255 ) ;
motorSpeedA =
motorSpeedA + xMapped;
motorSpeedB =
motorSpeedB - xMapped;
eğer (
motorSpeedA> 255 ) {
motorSpeedA =
255 ;
}
eğer ( motorSpeedB
< 0 ) {
motorSpeedB = 0
;
}
}
eğer ( motorSpeedA
< 70 ) {
motorSpeedA = 0 ;
}
eğer ( motorSpeedB
< 70 ) {
motorSpeedB = 0 ;
}
analogWrite ( enA,
motorSpeedA ) ;
analogWrite ( enB,
motorSpeedB ) ;
}
Hiç yorum yok:
Yorum Gönder