Skip to content

Commit

Permalink
Added support for buzzer. (bluetooth now default off)
Browse files Browse the repository at this point in the history
  • Loading branch information
malx122 committed Jan 27, 2012
1 parent 326c59f commit 6e85f34
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//#define BAUDRATE 230400

//Do you have a second serial you want activated (for bluetooth as example)
#define SECOND_SERIAL MSerial1
#define SECOND_SERIAL_BAUDRATE 115200
//#define SECOND_SERIAL MSerial1
//#define SECOND_SERIAL_BAUDRATE 115200

// Chuck size for fast sd transfer
#define SD_FAST_XFER_CHUNK_SIZE 1024
Expand Down
4 changes: 1 addition & 3 deletions Marlin/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
#endif

#include "MarlinSerial.h"
#ifdef SECOND_SERIAL
#include "SerialManager.h"
#endif //SECOND_SERIAL
#include "SerialManager.h"


#ifndef cbi
Expand Down
12 changes: 11 additions & 1 deletion Marlin/Marlin.pde
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "ultralcd.h"
#include "led.h"
#include "buzzer.h"
#include "planner.h"
#include "stepper.h"
#include "temperature.h"
Expand Down Expand Up @@ -275,6 +276,7 @@ void setup()
#if (LED_PIN > -1)
led_init();
#endif
buzzer_init();
setup_photpin();
}

Expand Down Expand Up @@ -1195,7 +1197,15 @@ FORCE_INLINE void process_commands()
SERIAL_ECHO(freeMemory());
}
break;

case 601: //Play tone
{
int tone = 1915;
int duration = 300;
if(code_seen('T')) tone = code_value() ;
if(code_seen('D')) duration = code_value() ;
playTone(tone, duration);
}
break;
}
}

Expand Down
36 changes: 36 additions & 0 deletions Marlin/buzzer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "buzzer.h"
#ifdef BUZZER_PIN
#if (BUZZER_PIN > -1)
void buzzer_init()
{
SET_OUTPUT(BUZZER_PIN);
WRITE(BUZZER_PIN, LOW);

}

void playTone(int tone, int duration)
{
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(BUZZER_PIN, HIGH);
delayMicroseconds(tone);
digitalWrite(BUZZER_PIN, LOW);
delayMicroseconds(tone);
}
}

void playNote(char note, int duration) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}

#endif
#endif //BUZZER_PIN


17 changes: 17 additions & 0 deletions Marlin/buzzer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef __BUZZERH
#define __BUZZERH

#include "Marlin.h"

#if (defined(BUZZER_PIN) && (BUZZER_PIN > -1))
void buzzer_init();
void playTone(int tone, int duration);
void playNote(char note, int duration);

#else
FORCE_INLINE void buzzer_init() {};
FORCE_INLINE void playTone(int tone, int duration) {};
FORCE_INLINE void playNote(char note, int duration) {};
#endif

#endif
1 change: 1 addition & 0 deletions Marlin/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@
/*#define PROBE_PIN 11*/

#define LED_PIN 27
#define BUZZER_PIN 28

#define FAN_PIN -1

Expand Down

0 comments on commit 6e85f34

Please sign in to comment.