Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
JSH_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박진형
2020-05-20 22:55:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
685aa1909287871cc95d7229f3c93b83ae93c6bc
685aa190
1 parent
bf663c29
Add arduino file.
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
arduino/arduino.ino
arduino/arduino.ino
0 → 100644
View file @
685aa19
int
actu
=
6
;
const
int
xInput
=
A0
;
const
int
yInput
=
A1
;
const
int
zInput
=
A2
;
// initialize minimum and maximum Raw Ranges for each axis
int
RawMin
=
0
;
int
RawMax
=
1023
;
int
temp_x
=
0
;
int
temp_y
=
0
;
int
temp_z
=
0
;
// Take multiple samples to reduce noise
const
int
sampleSize
=
10
;
void
setup
()
{
pinMode
(
actu
,
OUTPUT
);
analogReference
(
EXTERNAL
);
Serial
.
begin
(
115200
);
}
void
loop
()
{
//Read raw values
int
xRaw
=
ReadAxis
(
xInput
)
-
temp_x
;
int
yRaw
=
ReadAxis
(
yInput
)
-
temp_y
;
int
zRaw
=
ReadAxis
(
zInput
)
-
temp_z
;
int
result
=
(
abs
(
xRaw
)
+
abs
(
yRaw
)
+
abs
(
zRaw
))
/
3
;
temp_x
=
ReadAxis
(
xInput
);
temp_y
=
ReadAxis
(
yInput
);
temp_z
=
ReadAxis
(
zInput
);
// Convert raw values to 'milli-Gs"
long
xScaled
=
map
(
xRaw
,
RawMin
,
RawMax
,
-
3000
,
3000
);
long
yScaled
=
map
(
yRaw
,
RawMin
,
RawMax
,
-
3000
,
3000
);
long
zScaled
=
map
(
zRaw
,
RawMin
,
RawMax
,
-
3000
,
3000
);
// re-scale to fractional Gs
float
xAccel
=
xScaled
/
1000.0
;
float
yAccel
=
yScaled
/
1000.0
;
float
zAccel
=
zScaled
/
1000.0
;
Serial
.
print
(
"X, Y, Z :: "
);
Serial
.
print
(
xRaw
);
Serial
.
print
(
", "
);
Serial
.
print
(
yRaw
);
Serial
.
print
(
", "
);
Serial
.
print
(
zRaw
);
Serial
.
print
(
" :: "
);
Serial
.
print
(
xAccel
,
0
);
Serial
.
print
(
"G, "
);
Serial
.
print
(
yAccel
,
0
);
Serial
.
print
(
"G, "
);
Serial
.
print
(
zAccel
,
0
);
Serial
.
print
(
"G"
);
Serial
.
print
(
" :: "
);
Serial
.
println
(
result
);
if
(
result
<
0
){
result
=
0
;
}
analogWrite
(
actu
,
result
-
3
);
delay
(
50
);
}
// Take samples and return the average
int
ReadAxis
(
int
axisPin
)
{
long
reading
=
0
;
analogRead
(
axisPin
);
delay
(
1
);
for
(
int
i
=
0
;
i
<
sampleSize
;
i
++
)
{
reading
+=
analogRead
(
axisPin
);
}
return
reading
/
sampleSize
;
}
Please
register
or
login
to post a comment