Current File : /home/jeshor13/11bsouth.com/HonkBoard0.1/sketch.js
// Jesse Horwitz Nov 5 2015

var honkSoundLevels = [83, 77, 70, 71, 72, 76, 88, 98, 88, 92, 103, 93, 74, 86, 90, 80, 90, 96, 107, 166, 190, 182, 184, 227, 233, 206, 139, 107, 85, 74, 75, 74, 74, 78, 77, 72, 71, 88, 110, 184, 220, 221, 188, 120, 109, 130, 207, 239, 237, 201, 120, 93, 72, 78, 90, 81, 77, 94, 95, 145, 189, 198, 174, 114, 107, 100, 90, 114, 122, 127, 188, 210, 200, 153, 96, 95, 80, 93, 106, 146, 201, 219, 204, 151, 98, 93, 87, 94, 102, 88, 91, 120, 122, 143, 180, 188, 169, 143, 130, 121, 168, 194, 188, 147, 100, 90, 86, 97, 103, 95, 80, 85, 87, 85, 137, 157, 148, 168, 202, 205, 173, 149, 149, 119, 90, 98, 97, 97, 92, 85, 75, 80, 84, 83, 79, 81, 84, 77, 103, 117, 115, 143, 157, 140, 107, 103, 96, 90, 87, 78, 75, 79, 81, 77, 76, 87, 95, 89, 86, 95, 97, 121, 132, 122, 117, 162, 179, 165, 124, 104, 97, 89, 85, 86, 81, 83, 84, 81, 87, 96, 101, 98, 99, 93, 75, 92, 116, 107, 121, 165, 174, 151, 96, 91, 86, 83, 80, 71, 70, 77, 81, 90, 116, 119, 97, 81, 80, 81, 81, 96, 111, 100, 111, 129, 119, 92, 82, 79, 66, 70, 74, 83, 106, 118, 103, 65, 69, 81, 81, 64, 54, 62, 59, 66, 66, 57, 81, 99, 89, 51, 33, 33, 47, 57, 47, 26, 13, 20, 36, 32, 25, 41, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
var honkCount = 0
var honkCount0 = 0
var headlineText = "Your Honks"
var midlineText = "Today's Conditions:"
var bottomlineText = "Total Honks This Week:"
var modeSelector;
var mode = 'Sign';
var fft;
var mic;
var p_spectrum = []
var p_spectrumMax = [0]
var p_spectrumAvg = []
var spectrum = [];
var backgroundHonkTimer = 0
var leastSq = 0



function preload() {
  externalMedia() // see media.js for external files
}

function setup() {
  createCanvas(windowWidth, windowHeight * 0.90) // create canvas using full display width and 90% of height
    //

  selector = createSelect();
  selector.option('Settings');
  selector.option('Data');
  selector.option('Sign');
  selector.changed(selectorEvent);
  //
 // mic = new p5.AudioIn();
  //mic.start();
  fft = new p5.FFT();
  //fft.setInput(mic);
  for (i = 0; i < 1023; i++) {
    p_spectrumMax[i] = int(0)
  }
  carHorns = [carHornsLong, carHornsShort, carHornsShort2,
    carHornsLong2, carHornsLong3, carHornOne,streetSound
  ];
  carHorns[6].play()
}

function draw() {
  //playHonkSound()
  spectrum = fft.analyze();
  if (mode == 'Sign') {
    basicSign()
  }
  if (mode == 'Data') {
    consoleData()
  }
  if (mode == 'Settings') {
    consoleSettings()
  }

}

function selectorEvent() {
  mode = selector.value()
}


function playHonkSound() {
  if (millis() - backgroundHonkTimer > 6000) {
    var i = int(random(0, 4))
    carHorns[i].play();
    backgroundHonkTimer = millis()
  }

}