-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblue-l298h-editert-asle.ino
92 lines (75 loc) · 1.98 KB
/
blue-l298h-editert-asle.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
#define m1 3
#define m2 5
#define m3 9
#define m4 10
//Denne virker 2019-06-22 Asle
int data=0,kec=0;
boolean forward=true;
int fast[11]={0,80,100,120,140,160,180,200,220,240,255};
void setup()
{
pinMode(m1,OUTPUT);
pinMode(m2,OUTPUT);
pinMode(m3,OUTPUT);
pinMode(m4,OUTPUT);
mySerial.begin(9600);
}
void motorOut(unsigned char lpwm, unsigned char rpwm, boolean arrow){
if(arrow==false){
digitalWrite(m3,HIGH);
digitalWrite(m1,LOW);
analogWrite(m4,255-lpwm);
analogWrite(m2,rpwm);
}
else{
digitalWrite(m3,LOW);
digitalWrite(m1,HIGH);
analogWrite(m4,lpwm);
analogWrite(m2,255-rpwm);
}
}
void loop(){
if(mySerial.available()>0){
data=mySerial.read();
if (data =='0') { kec=0;}
else if (data =='1') { kec=1;}
else if (data =='2') { kec=2;}
else if (data =='3') { kec=3;}
else if (data =='4') { kec=4;}
else if (data =='5') { kec=5;}
else if (data =='6') { kec=6;}
else if (data =='7') { kec=7;}
else if (data =='8') { kec=8;}
else if (data =='9') { kec=9;}
else if (data =='q') {kec=10;}
//S= Stop
if (data == 'S')
{ motorOut(0,0,false); }
//F=Forward
if (data=='F')
{ motorOut(fast[kec],fast[kec],true); }
//I=turn right forward
if (data=='I')
{ motorOut(fast[kec],((fast[kec])/2),true);}
//G=turn left forward
if (data=='G')
{ motorOut(((fast[kec])/2),fast[kec],true); }
//R=turn right
if(data=='R')
{ motorOut(fast[kec],0,true); }
//L=turn left
if(data=='L')
{ motorOut(0,fast[kec],true); }
//B=back
if(data=='B')
{ motorOut(fast[kec],fast[kec],false); }
//H=turn left back
if (data=='H')
{ motorOut(((fast[kec])/2),fast[kec],false); }
//turn right back
if (data=='J')
{ motorOut(fast[kec],((fast[kec])/2),false); }
}
}