DOWNLOAD: Open Door Volume Control

Open Door Volume Control (ODVC)
Für den Club Heartbeat soll ein kleines Tool mit einer simplen Hardwarelösung gefunden werden, um die Lautstärke der Musik automatisch nach unten zu regeln, sobald eine der beiden Türen geöffnet wird, um so den Lautstärkepegel außerhalb zu minimieren.

Die Hardwareumsetzung erfolgt mittels eines Arduino Duemilanove und zwei Reedkontakten. Das Board wird per USB an den Rechner angeschlossen und so auch mit Strom versorgt.

Hier der Code für das Arduino Board:

—–begin—–
int ledPin = 13; // LED connected to digital pin 13
int button1Pin = 8; // Button1 connected to digital pin 8
int button2Pin = 7; // Button2 connected to digital pin 7
boolean doorOpen = false; // door status flag

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the serial interface
Serial.begin(9600);
// initialize the digital LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the digital Button1 pin as an input
pinMode(button1Pin,INPUT);
// enable the internal pullup resistor
digitalWrite(button1Pin,HIGH);
// same procedure for Button2 pin
pinMode(button2Pin,INPUT);
digitalWrite(button2Pin,HIGH);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
// check if input on one of both pins is low (means door is open) and door status flag is set to false (door was opened while this cycle of the loop)
if (((digitalRead(button2Pin) == LOW) | (digitalRead(button1Pin) == LOW))& (doorOpen == false)) {
digitalWrite(ledPin, HIGH); // lighten the control LED
Serial.print(“1″); // send status 1 over serial interface (door open)
doorOpen = true; // set door status flag to true (avoids “spam” in the communication over the serial interface )
}

// check if input on both pins is high (means doors are closed) and door status flag is set to true (door was closed while this cycle of the loop)
if ((digitalRead(button2Pin) == HIGH) & (digitalRead(button1Pin) == HIGH) & (doorOpen == true)) {
digitalWrite(ledPin, LOW); // switch off the control LED
Serial.print(“0″); // send status 0 over serial interface (doors closed)
doorOpen = false; // set door status flag to false
}
}
—–end—–

Hier der Code für das eigentliche Open Door Volume Control Tool (C#):


namespace VolumeTool
{
    partial class Form1
    {
        /// <summary>
        /// Erforderliche Designervariable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Verwendete Ressourcen bereinigen.
        /// </summary>
        /// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Vom Windows Form-Designer generierter Code

        /// <summary>
        /// Erforderliche Methode für die Designerunterstützung.
        /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
        /// </summary>
        private void InitializeComponent()
        {
            this.trackWave = new System.Windows.Forms.TrackBar();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            ((System.ComponentModel.ISupportInitialize)(this.trackWave)).BeginInit();
            this.SuspendLayout();
            // 
            // trackWave
            // 
            this.trackWave.Location = new System.Drawing.Point(12, 12);
            this.trackWave.Name = "trackWave";
            this.trackWave.Size = new System.Drawing.Size(268, 42);
            this.trackWave.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(205, 60);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "Test";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Visible = false;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.ForeColor = System.Drawing.Color.Yellow;
            this.label1.Location = new System.Drawing.Point(12, 65);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(130, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Volume Control: False";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(12, 89);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBox1.Size = new System.Drawing.Size(265, 159);
            this.textBox1.TabIndex = 3;
            this.textBox1.Visible = false;
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(20, 255);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(35, 13);
            this.label2.TabIndex = 4;
            this.label2.Text = "label2";
            this.label2.Visible = false;
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(19, 45);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(13, 13);
            this.label3.TabIndex = 5;
            this.label3.Text = "0";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(254, 45);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(25, 13);
            this.label4.TabIndex = 6;
            this.label4.Text = "100";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 88);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.trackWave);
            this.MaximumSize = new System.Drawing.Size(300, 115);
            this.MinimumSize = new System.Drawing.Size(300, 115);
            this.Name = "Form1";
            this.Text = "ODVC (Open Door Volume Control)";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.trackWave)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.TrackBar trackWave;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
    }
}


An dieser Stelle bedanke ich mich nochmal kräftig bei Florian Weinert für seine Hilfe und Einsatzbereitschaft.