torstengeppert
Published © GPL3+

Hit'n'Blink

LED patterns triggered by beats (physical force, NOT sound)

BeginnerProtip1,352
Hit'n'Blink

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
LED ring 24 LEDs
×1
Resistor 220 ohm
Resistor 220 ohm
×4
Rotary potentiometer (generic)
Rotary potentiometer (generic)
10 kOhm
×1
Piezo Pressure Sensor
×1
Battery Holder, AA x 4
Battery Holder, AA x 4
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Heat Shrinking Tube

Story

Read more

Schematics

Schematics for Hit'n'Blink.

Code

Hit

Arduino
/*
 * Visualization of drum sticks hitting drum pad
 * LED ring and/or stripe (selectable by external switch, see schematics) w/ selectable
 *  - color pattern (based on input from potentiometer)
 *  - brighntess depends on how hard the drum stick hits the drum pad
 *  Drum stick hitting drum pad is detected by a simple piezo sensor placed underneath the drum pad
 * 
 * Written by T. Geppert, April 2020
 */

/*
 * Constants and alike
 */
// LED stuff =============================================================================
// LED Ring / Stripe ---------------------------------------------------------------------
#include <FastLED.h>
#define NUM_LEDS 24                       // Number of LEDs in ring
#define LED_DATA_PIN 9                   // Data Pin for control of LEDs in strip 1

CRGB leds[NUM_LEDS];                    // create array for LED ring

#define LED_HUE_STD 13                       // STandarD HUE = "color" of LED; 0~red, 32~orange, 64~yellow
#define LED_SAT_STD 255                     // STandarD SATuration = saturation of color of LED; 0~neutral grey, 255~pure color
#define LED_VAL_STD 100 

int LED_HUE = LED_HUE_STD;                  // HUE used for FastLED depending on input conditions
int LED_SAT = LED_SAT_STD;                  // SAT used for FastLED depending on input conditions
int LED_VAL = LED_VAL_STD;                  // VAL used for FastLED depending on input conditions

// LED red/yellow/green ----------------------------------------------------------------------
#define LED_RED_PIN 3
#define LED_YELLOW_PIN 4
#define LED_GREEN_PIN 5

// Vibration sensor =============================================================================
#define VIB_SENS_PIN_1 A1                   // Input from vibration sensor 1
int VibRead_1;

// Other stuff =============================================================================
#define LEDMode_PIN A3
int trigLim = 100;                        // trigger limit for vibration sensor
int beatsCount = 0;                         // counts number of beats (limits for red, yellow, green can be set below)

int beatsRedLim = 192;
int beatsYellowLim = 384;
int beatsGreenLim = 1536;

int switchOnDelay = 2;                   // time  (ms) between switchin on subsequent LEDs

/*
 * Setup ===================================================================================
 */
void setup() {
  Serial.begin(9600);
  FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, NUM_LEDS);    // setup LED ring

  pinMode(LED_DATA_PIN, OUTPUT);
  pinMode(LEDMode_PIN, INPUT);

  pinMode(LED_RED_PIN, OUTPUT);
  pinMode(LED_YELLOW_PIN, OUTPUT);
  pinMode(LED_GREEN_PIN, OUTPUT);

  pinMode(VIB_SENS_PIN_1, INPUT);

}
/*
 * End of Setup ===================================================================================
 */

/*
 * Main Loop ===================================================================================
 */
 
void loop() {
  LED_HUE = LED_HUE_STD;                  // HUE used for FastLED depending on input conditions
  LED_SAT = LED_SAT_STD;                  // SAT used for FastLED depending on input conditions
  LED_VAL = LED_VAL_STD;                  // VAL used for FastLED depending on input conditions

  // Wait until vibration sensor detects something
  VibRead_1 = 0;
  while( VibRead_1 < trigLim ) {
    VibRead_1 = analogRead(VIB_SENS_PIN_1);       // VibRead_1 used as trigger as well as determining brightness of LEDs
//Serial.println("Waiting for input from vibration sensor");
  }

  beatsCount = beatsCount + 1;                    // increase number of beats
  // turn on red, yellow or green LED, depending on number of total beats
  if (beatsCount <= beatsYellowLim) {
    digitalWrite(LED_RED_PIN, HIGH);
  }
  if (beatsCount > beatsYellowLim && beatsCount < beatsGreenLim) {
    digitalWrite(LED_YELLOW_PIN, HIGH);
  }
  if (beatsCount > beatsGreenLim) {
    digitalWrite(LED_GREEN_PIN, HIGH);
  }
  
  LED_VAL = map(VibRead_1, 0, 1023, 0, 255);      // derive brightness values for LEDs from magnitude of vibration
/*Serial.println();
Serial.println(VibRead_1);
Serial.println(LED_VAL);
*/  
/*Serial.print("Vib Sens 1: ");
Serial.print(VibSens_1);
Serial.print(" Vib Read 1: ");
Serial.println(VibRead_1);
*/
  
  int LEDMode = analogRead(LEDMode_PIN);  // value used for selection of color pattern
  
/*Serial.print("LEDMode: ");
Serial.println(LEDMode);
*/

  // set LED HUE etc. depending on input
  if (0 < LEDMode && LEDMode < 250) {
    LED_HUE = 2;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (250 < LEDMode && LEDMode < 500) {
    LED_HUE = 80;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (500 < LEDMode && LEDMode < 700) {
    LED_HUE = 150;
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }
  if (700 < LEDMode && LEDMode < 1023) {
    for (int i=0; i<NUM_LEDS; i++) {
      leds[i]=CHSV(int(192/NUM_LEDS*i), LED_SAT, LED_VAL);
      FastLED.show();
      delay(switchOnDelay);
    }
  }

  //Turn all LEDs OFF
  digitalWrite(LED_RED_PIN, LOW);
  digitalWrite(LED_YELLOW_PIN, LOW);
  digitalWrite(LED_GREEN_PIN, LOW);
  for (int i=0; i<NUM_LEDS; i++) {
    LED_HUE = 0;
    LED_SAT = 0;
    LED_VAL = 0;
    leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL);
    FastLED.show();
    delay(switchOnDelay);
  }

}
/*
 * End of Main Loop  ===================================================================================
 */

Credits

torstengeppert

torstengeppert

0 projects • 4 followers

Comments