Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Sam Guyer
Lightsaber
Commits
6ab6c74f
Commit
6ab6c74f
authored
Oct 27, 2015
by
Sam Guyer
Browse files
Added sounds
parent
8ab8ad34
Changes
1
Hide whitespace changes
Inline
Side-by-side
Lightsaber.ino
View file @
6ab6c74f
...
...
@@ -11,6 +11,11 @@
// Segments, in order from bottom to top on the blade
int
SEG_PIN
[
NUM_SEGMENTS
]
=
{
12
,
11
,
10
,
9
,
6
,
5
,
3
};
// -- Sounds -------------------------------
#define SABER_ON_SOUND_PIN 8
#define SABER_OFF_SOUND_PIN 7
// -- Button -------------------------------
#define BUTTON_PIN 2
...
...
@@ -58,24 +63,18 @@ public:
}
}
void
activate
()
{
m_state
=
Activate
;
}
void
deactivate
()
{
m_state
=
Deactivate
;
}
void
toggle
()
{
if
(
m_state
==
On
||
m_state
==
Activate
)
{
m_state
=
Deactivate
;
m_time
=
millis
();
digitalWrite
(
SABER_ON_SOUND_PIN
,
LOW
);
Serial
.
println
(
"ON"
);
}
else
if
(
m_state
==
Off
|
m_state
==
Deactivate
)
{
m_state
=
Activate
;
m_time
=
millis
();
digitalWrite
(
SABER_OFF_SOUND_PIN
,
LOW
);
Serial
.
println
(
"OFF"
);
}
}
...
...
@@ -99,6 +98,11 @@ public:
m_level
=
map
(
current
-
m_time
,
0
,
m_time_to_deactivate
,
m_total_length
,
0
);
}
}
if
((
current
-
m_time
)
>
100
)
{
digitalWrite
(
SABER_ON_SOUND_PIN
,
HIGH
);
digitalWrite
(
SABER_OFF_SOUND_PIN
,
HIGH
);
}
render
();
}
...
...
@@ -159,10 +163,15 @@ Blade blade(SEG_PIN, NUM_SEGMENTS);
void
setup
()
{
delay
(
5
00
);
delay
(
2
00
);
Serial
.
begin
(
9600
);
blade
.
init
();
pinMode
(
SABER_ON_SOUND_PIN
,
OUTPUT
);
digitalWrite
(
SABER_ON_SOUND_PIN
,
HIGH
);
pinMode
(
SABER_OFF_SOUND_PIN
,
OUTPUT
);
digitalWrite
(
SABER_OFF_SOUND_PIN
,
HIGH
);
pinMode
(
BUTTON_PIN
,
INPUT
);
button
.
init
();
...
...
Write
Preview
Markdown
is supported
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