Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Patrick Engelbrecht Sørensen
EduFarm - Tractor Project
Commits
c84fabd9
Commit
c84fabd9
authored
Dec 13, 2021
by
Patrick Engelbrecht Sørensen
Browse files
Delete motor_master_v4.ino
parent
5a0ff26b
Changes
1
Hide whitespace changes
Inline
Side-by-side
motor_master_v4.ino
deleted
100644 → 0
View file @
5a0ff26b
#include
<Wire.h>
#define greenLED 12
#define yellowLED 11
#define brownLED 9
#define orangeLED 10
#define attachmentGreen A3
#define attachmentRed A2
#define buzzerPin A1
int
c
=
0
;
boolean
beepSucceed
=
false
;
boolean
beepFailed
=
false
;
//L293D
//Motor A
const
int
enA
=
6
;
// Pin 7 of L293
const
int
motorPin1
=
8
;
// Pin 1 of L293
const
int
motorPin2
=
7
;
// Pin 2 of L293
//Motor B
const
int
enB
=
3
;
// Pin 9 of L293
const
int
motorPin3
=
2
;
// Pin 10 of L293
const
int
motorPin4
=
4
;
// Pin 15 of L293
void
setup
()
{
Wire
.
begin
();
// join i2c bus (address optional for master)
Serial
.
begin
(
9600
);
// start serial for output
pinMode
(
greenLED
,
OUTPUT
);
pinMode
(
yellowLED
,
OUTPUT
);
pinMode
(
brownLED
,
OUTPUT
);
pinMode
(
orangeLED
,
OUTPUT
);
pinMode
(
attachmentGreen
,
OUTPUT
);
pinMode
(
attachmentRed
,
OUTPUT
);
pinMode
(
motorPin1
,
OUTPUT
);
pinMode
(
motorPin2
,
OUTPUT
);
pinMode
(
motorPin3
,
OUTPUT
);
pinMode
(
motorPin4
,
OUTPUT
);
pinMode
(
enA
,
OUTPUT
);
pinMode
(
enB
,
OUTPUT
);
pinMode
(
buzzerPin
,
OUTPUT
);
tone
(
buzzerPin
,
523
,
125
);
delay
(
100
);
noTone
(
buzzerPin
);
}
void
loop
()
{
Wire
.
requestFrom
(
8
,
1
);
// request 6 bytes from slave device #8
while
(
Wire
.
available
())
{
// slave may send less than requested
c
=
Wire
.
read
();
// receive a byte as character
Serial
.
print
(
c
);
// print the character
}
if
(
c
==
1
)
{
digitalWrite
(
greenLED
,
HIGH
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
digitalWrite
(
orangeLED
,
LOW
);
}
else
if
(
c
==
2
)
{
digitalWrite
(
yellowLED
,
HIGH
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
digitalWrite
(
orangeLED
,
LOW
);
}
else
if
(
c
==
3
)
{
digitalWrite
(
orangeLED
,
HIGH
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
}
else
if
(
c
==
4
)
{
digitalWrite
(
brownLED
,
HIGH
);
digitalWrite
(
orangeLED
,
LOW
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
greenLED
,
LOW
);
}
else
if
(
c
==
5
)
{
digitalWrite
(
attachmentGreen
,
HIGH
);
digitalWrite
(
attachmentRed
,
LOW
);
digitalWrite
(
greenLED
,
HIGH
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
orangeLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
}
else
if
(
c
==
6
)
{
digitalWrite
(
attachmentGreen
,
HIGH
);
digitalWrite
(
attachmentRed
,
LOW
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
yellowLED
,
HIGH
);
digitalWrite
(
orangeLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
}
else
if
(
c
==
7
)
{
digitalWrite
(
attachmentGreen
,
HIGH
);
digitalWrite
(
attachmentRed
,
LOW
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
orangeLED
,
HIGH
);
digitalWrite
(
brownLED
,
LOW
);
}
else
if
(
c
==
8
)
{
digitalWrite
(
attachmentGreen
,
HIGH
);
digitalWrite
(
attachmentRed
,
LOW
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
orangeLED
,
LOW
);
digitalWrite
(
brownLED
,
HIGH
);
}
else
{
digitalWrite
(
attachmentGreen
,
LOW
);
digitalWrite
(
attachmentRed
,
HIGH
);
digitalWrite
(
greenLED
,
LOW
);
digitalWrite
(
yellowLED
,
LOW
);
digitalWrite
(
orangeLED
,
LOW
);
digitalWrite
(
brownLED
,
LOW
);
}
if
(
c
==
5
||
c
==
6
||
c
==
7
||
c
==
8
)
{
normalSpeed
();
forward
();
if
(
beepSucceed
==
false
){
buzzerSuccess
();
beepSucceed
=
true
;
beepFailed
=
false
;
}
}
else
if
(
c
==
9
)
{
rightTurn
();
}
else
if
(
c
==
10
)
{
leftTurn
();
}
else
{
stopDriving
();
if
(
beepFailed
==
false
){
buzzerFail
();
beepFailed
=
true
;
beepSucceed
=
false
;
}
}
}
void
forward
()
{
digitalWrite
(
motorPin1
,
HIGH
);
digitalWrite
(
motorPin2
,
LOW
);
digitalWrite
(
motorPin3
,
HIGH
);
digitalWrite
(
motorPin4
,
LOW
);
}
void
leftTurn
()
{
analogWrite
(
enA
,
247
);
analogWrite
(
enB
,
70
);
digitalWrite
(
motorPin1
,
HIGH
);
digitalWrite
(
motorPin2
,
LOW
);
digitalWrite
(
motorPin3
,
HIGH
);
digitalWrite
(
motorPin4
,
LOW
);
}
void
rightTurn
()
{
analogWrite
(
enA
,
73
);
analogWrite
(
enB
,
255
);
digitalWrite
(
motorPin1
,
HIGH
);
digitalWrite
(
motorPin2
,
LOW
);
digitalWrite
(
motorPin3
,
HIGH
);
digitalWrite
(
motorPin4
,
LOW
);
}
void
stopDriving
()
{
digitalWrite
(
motorPin1
,
LOW
);
digitalWrite
(
motorPin2
,
LOW
);
digitalWrite
(
motorPin3
,
LOW
);
digitalWrite
(
motorPin4
,
LOW
);
}
void
normalSpeed
()
{
analogWrite
(
enA
,
247
);
analogWrite
(
enB
,
255
);
}
void
buzzerSuccess
()
{
tone
(
buzzerPin
,
523
,
125
);
delay
(
100
);
tone
(
buzzerPin
,
587
,
125
);
delay
(
100
);
tone
(
buzzerPin
,
659
,
125
);
delay
(
100
);
noTone
(
buzzerPin
);
}
void
buzzerFail
()
{
tone
(
buzzerPin
,
523
,
125
);
delay
(
100
);
tone
(
buzzerPin
,
440
,
125
);
delay
(
100
);
tone
(
buzzerPin
,
349
,
125
);
delay
(
100
);
tone
(
buzzerPin
,
262
,
125
);
delay
(
100
);
noTone
(
buzzerPin
);
}
Write
Preview
Supports
Markdown
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