Commit 6ab6c74f authored by Sam Guyer's avatar Sam Guyer
Browse files

Added sounds

parent 8ab8ad34
......@@ -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(500);
delay(200);
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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment