Code Piezo LEDs

#include "FastLED.h"

//#include <RingBuf.h>

 

#define NUM_LEDS 24

#define DATA_PIN 8

#define sensorPin_1 A1

#define sensorPin_2 A2

#define sensorPin_3 A3

#define buzzerPin A4

#define potiPin A0

 

#define MAX_POWER_MILLIAMPS 5000

CRGB leds[NUM_LEDS];

 

//RingBuf<int, 500> myBuffer;

//int i = 0;          

 

int brightness = 0;

int hue = 15;      //Hue-Range: 0=gelbrosa, 31= gelbgrün, 63=grün, 94=blaugrün, 127=(grün)blau, 158=blaublaub, 190=lilablau, 221=lila(blaurosa), 255=gelbrosa

 

int val_1;

int val_2;

int val_3;

int delayedValue;

 

int threshold;

 

void setup() {

  Serial.begin(115200);

  Serial.print("Inizializing FastLED..");

  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

  Serial.println("Done");

  Serial.print("hue");

  Serial.println(hue);

 

  pinMode(sensorPin_1, INPUT);

  pinMode(sensorPin_2, INPUT);

  pinMode(sensorPin_3, INPUT);

  pinMode(buzzerPin, OUTPUT);

  pinMode(potiPin, OUTPUT);

 

 

}

 

void loop() {

 

  val_1 = analogRead(sensorPin_1);  //reads incoming value on Pin A1

  val_2 = analogRead(sensorPin_2);

  val_3 = analogRead(sensorPin_3);

  threshold = analogRead(potiPin);

 

  // take the lowest Sensor Value as an input for the Lights //

  // it is called delayedValue because of the Ringbuffer    //

 

  if (val_1 > val_2 && val_1 > val_3) {

    delayedValue = val_1;

  } else if (val_2 > val_1 && val_2 > val_3) {

    delayedValue = val_2;

  } else if (val_3 > val_1 && val_3 > val_2) {

    delayedValue = val_3;

  }

 

  /////////  RINGBUFFER ////////////////

  //  myBuffer.push(delayedValue);

  //  if (i > 10) {

  //    myBuffer.pop(delayedValue);

  //  } else {

  //    i++;

  //  }

  //////////////////////////////////////

 

  Serial.print("\t val_1: ");

  Serial.print(val_1);

  Serial.print("\t val_2: ");

  Serial.print(val_2);

  Serial.print("\t val_3: ");

  Serial.print(val_3);

  Serial.print("\t threshold: ");

  Serial.print(threshold);

  Serial.print("\t dealyedValue: ");

  Serial.print(delayedValue);

 

  //// SOUND ///////////////////////////

 

  int pitch = map (delayedValue, 20, 1023, 200, 2500);

  //pitchConstr = constrain(pitch, 30,400);

  if (delayedValue > threshold) {

    tone(buzzerPin, pitch, 40);

    Serial.print("\t Buzzer active");

  }

 

  //// LIGHT ////////////////////////////

 

  brightness = map(delayedValue, 0, 1023, 50 , 255);

  for (uint16_t i = 0; i < NUM_LEDS; i++) {

    leds[i] = CHSV(hue, 100, brightness);

  }

 

  FastLED.show();

  Serial.print("\t brightness");

  Serial.println(brightness);

 

  delayedValue = 0;

 

  delay(10);

 

}