Created by
Created April 21, 2013
Last modified April 23, 2013
Tags No tags.

Summary

Not provided.


Description

// Configurable siren // by andersand.net

const int SOUND_PIN = 3;
const int POT_LOWER_PIN = 0;
const int POT_UPPER_PIN = 5;
const int POT_DELAY_PIN = 3;

const int PITCH_UPPER_LIMIT = 500;
const int PITCH_LOWER_LIMIT = 20;
const int DELAY_UPPER_LIMIT = 200;

const int STEP = 20;

int soundPitch = 20;
int soundPitchChange = STEP;

int soundDelay = 80;
int pitchLower = 20;
int pitchUpper = 500;

int rawLowerValue;
int rawUpperValue;
int rawDelayValue;

void setup() {
  Serial.begin(9600);
}

void loop() {
  // read and map input values:
  rawLowerValue = analogRead(POT_LOWER_PIN);
  rawUpperValue = analogRead(POT_UPPER_PIN);
  rawDelayValue = analogRead(POT_DELAY_PIN);
  pitchLower = map(rawLowerValue, 0, 1023, PITCH_LOWER_LIMIT, PITCH_UPPER_LIMIT);
  pitchUpper = map(rawUpperValue, 0, 1023, PITCH_LOWER_LIMIT, PITCH_UPPER_LIMIT);
  soundDelay = map(rawDelayValue, 0, 1023, 0, DELAY_UPPER_LIMIT);

  // output tone and delay
  tone(SOUND_PIN, soundPitch);
  delay(soundDelay);

  // prepare next tone:
  soundPitch += soundPitchChange;
  if (soundPitch > pitchUpper) {
    soundPitchChange = -STEP;
  }
  else if (soundPitch < pitchLower) {
    soundPitchChange = STEP;
  }

  Serial.println(String(pitchLower) + " " + String(pitchUpper) + " " + String(soundDelay));
}

Comments

No comments yet. Be the first!

Leave a Comment

Please sign in or create an account to comment.

Revision History

Only the circuit's creator can access stored revision history.