From 3592a18b90f5c6a02f43f2e3625aaddfb32b8513 Mon Sep 17 00:00:00 2001 From: Marian Sigler Date: Sat, 8 Jun 2013 20:51:08 +0200 Subject: initial commit --- monophon/monophon.ino | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 monophon/monophon.ino (limited to 'monophon') diff --git a/monophon/monophon.ino b/monophon/monophon.ino new file mode 100644 index 0000000..1643bd4 --- /dev/null +++ b/monophon/monophon.ino @@ -0,0 +1,54 @@ +// play monophon sounds on the tesla coil +// +// receives uint16s from serial which specify the tone length in microseconds (1000000/440 is an "a" etc) + + +int pin1 = 4; +int pin2 = 5; +unsigned int tonelength = 0; +float high_factor = .2; + +void setup () { + pinMode(pin1, OUTPUT); + pinMode(pin2, OUTPUT); + Serial.begin(9600); +} + +void loop() { + while ( true ) { + if ( Serial.available() > 1 ) { + tonelength = Serial.read() << 8; + tonelength |= Serial.read(); + Serial.print("New tonelength: "); + Serial.println(tonelength); + } + if ( tonelength == 0 ) + delayMicroseconds(10); + else + beep(tonelength); + } +} + +void beep(long usecs) { + high(); + delayMicroseconds(usecs*high_factor); +// delayMicroseconds(usecs*on_percentage/100); + low(); + delayMicroseconds(usecs*(1-high_factor)); +// delayMicroseconds(usecs*(100-on_percentage)/100); +} + +void high() { + digitalWrite(pin1, HIGH); + digitalWrite(pin2, HIGH); +} + +void low() { + digitalWrite(pin1, LOW); + digitalWrite(pin2, LOW); +} + +long freq (double f) { + // convert frequency to tonelength + return 1000000/f; +} -- cgit v1.2.3-1-g7c22