Components and supplies
5 mm LED: Red
LED ring 24 LEDs
Rotary potentiometer (generic)
Resistor 220 ohm
5 mm LED: Green
Arduino Nano R3
Piezo Pressure Sensor
5 mm LED: Yellow
Battery Holder, AA x 4
Tools and machines
Soldering iron (generic)
Heat Shrinking Tube
Solder Wire, Lead Free
Project description
Code
Hit
arduino
1/* 2 * Visualization of drum sticks hitting drum pad 3 * LED ring and/or stripe (selectable by external switch, see schematics) w/ selectable 4 * - color pattern (based on input from potentiometer) 5 * - brighntess depends on how hard the drum stick hits the drum pad 6 * Drum stick hitting drum pad is detected by a simple piezo sensor placed underneath the drum pad 7 * 8 * Written by T. Geppert, April 2020 9 */ 10 11/* 12 * Constants and alike 13 */ 14// LED stuff ============================================================================= 15// LED Ring / Stripe --------------------------------------------------------------------- 16#include <FastLED.h> 17#define NUM_LEDS 24 // Number of LEDs in ring 18#define LED_DATA_PIN 9 // Data Pin for control of LEDs in strip 1 19 20CRGB leds[NUM_LEDS]; // create array for LED ring 21 22#define LED_HUE_STD 13 // STandarD HUE = "color" of LED; 0~red, 32~orange, 64~yellow 23#define LED_SAT_STD 255 // STandarD SATuration = saturation of color of LED; 0~neutral grey, 255~pure color 24#define LED_VAL_STD 100 25 26int LED_HUE = LED_HUE_STD; // HUE used for FastLED depending on input conditions 27int LED_SAT = LED_SAT_STD; // SAT used for FastLED depending on input conditions 28int LED_VAL = LED_VAL_STD; // VAL used for FastLED depending on input conditions 29 30// LED red/yellow/green ---------------------------------------------------------------------- 31#define LED_RED_PIN 3 32#define LED_YELLOW_PIN 4 33#define LED_GREEN_PIN 5 34 35// Vibration sensor ============================================================================= 36#define VIB_SENS_PIN_1 A1 // Input from vibration sensor 1 37int VibRead_1; 38 39// Other stuff ============================================================================= 40#define LEDMode_PIN A3 41int trigLim = 100; // trigger limit for vibration sensor 42int beatsCount = 0; // counts number of beats (limits for red, yellow, green can be set below) 43 44int beatsRedLim = 192; 45int beatsYellowLim = 384; 46int beatsGreenLim = 1536; 47 48int switchOnDelay = 2; // time (ms) between switchin on subsequent LEDs 49 50/* 51 * Setup =================================================================================== 52 */ 53void setup() { 54 Serial.begin(9600); 55 FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, NUM_LEDS); // setup LED ring 56 57 pinMode(LED_DATA_PIN, OUTPUT); 58 pinMode(LEDMode_PIN, INPUT); 59 60 pinMode(LED_RED_PIN, OUTPUT); 61 pinMode(LED_YELLOW_PIN, OUTPUT); 62 pinMode(LED_GREEN_PIN, OUTPUT); 63 64 pinMode(VIB_SENS_PIN_1, INPUT); 65 66} 67/* 68 * End of Setup =================================================================================== 69 */ 70 71/* 72 * Main Loop =================================================================================== 73 */ 74 75void loop() { 76 LED_HUE = LED_HUE_STD; // HUE used for FastLED depending on input conditions 77 LED_SAT = LED_SAT_STD; // SAT used for FastLED depending on input conditions 78 LED_VAL = LED_VAL_STD; // VAL used for FastLED depending on input conditions 79 80 // Wait until vibration sensor detects something 81 VibRead_1 = 0; 82 while( VibRead_1 < trigLim ) { 83 VibRead_1 = analogRead(VIB_SENS_PIN_1); // VibRead_1 used as trigger as well as determining brightness of LEDs 84//Serial.println("Waiting for input from vibration sensor"); 85 } 86 87 beatsCount = beatsCount + 1; // increase number of beats 88 // turn on red, yellow or green LED, depending on number of total beats 89 if (beatsCount <= beatsYellowLim) { 90 digitalWrite(LED_RED_PIN, HIGH); 91 } 92 if (beatsCount > beatsYellowLim && beatsCount < beatsGreenLim) { 93 digitalWrite(LED_YELLOW_PIN, HIGH); 94 } 95 if (beatsCount > beatsGreenLim) { 96 digitalWrite(LED_GREEN_PIN, HIGH); 97 } 98 99 LED_VAL = map(VibRead_1, 0, 1023, 0, 255); // derive brightness values for LEDs from magnitude of vibration 100/*Serial.println(); 101Serial.println(VibRead_1); 102Serial.println(LED_VAL); 103*/ 104/*Serial.print("Vib Sens 1: "); 105Serial.print(VibSens_1); 106Serial.print(" Vib Read 1: "); 107Serial.println(VibRead_1); 108*/ 109 110 int LEDMode = analogRead(LEDMode_PIN); // value used for selection of color pattern 111 112/*Serial.print("LEDMode: "); 113Serial.println(LEDMode); 114*/ 115 116 // set LED HUE etc. depending on input 117 if (0 < LEDMode && LEDMode < 250) { 118 LED_HUE = 2; 119 for (int i=0; i<NUM_LEDS; i++) { 120 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 121 FastLED.show(); 122 delay(switchOnDelay); 123 } 124 } 125 if (250 < LEDMode && LEDMode < 500) { 126 LED_HUE = 80; 127 for (int i=0; i<NUM_LEDS; i++) { 128 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 129 FastLED.show(); 130 delay(switchOnDelay); 131 } 132 } 133 if (500 < LEDMode && LEDMode < 700) { 134 LED_HUE = 150; 135 for (int i=0; i<NUM_LEDS; i++) { 136 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 137 FastLED.show(); 138 delay(switchOnDelay); 139 } 140 } 141 if (700 < LEDMode && LEDMode < 1023) { 142 for (int i=0; i<NUM_LEDS; i++) { 143 leds[i]=CHSV(int(192/NUM_LEDS*i), LED_SAT, LED_VAL); 144 FastLED.show(); 145 delay(switchOnDelay); 146 } 147 } 148 149 //Turn all LEDs OFF 150 digitalWrite(LED_RED_PIN, LOW); 151 digitalWrite(LED_YELLOW_PIN, LOW); 152 digitalWrite(LED_GREEN_PIN, LOW); 153 for (int i=0; i<NUM_LEDS; i++) { 154 LED_HUE = 0; 155 LED_SAT = 0; 156 LED_VAL = 0; 157 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 158 FastLED.show(); 159 delay(switchOnDelay); 160 } 161 162} 163/* 164 * End of Main Loop =================================================================================== 165 */ 166
Hit
arduino
1/* 2 * Visualization of drum sticks hitting drum pad 3 * LED ring 4 and/or stripe (selectable by external switch, see schematics) w/ selectable 5 6 * - color pattern (based on input from potentiometer) 7 * - brighntess depends 8 on how hard the drum stick hits the drum pad 9 * Drum stick hitting drum pad 10 is detected by a simple piezo sensor placed underneath the drum pad 11 * 12 * 13 Written by T. Geppert, April 2020 14 */ 15 16/* 17 * Constants and alike 18 19 */ 20// LED stuff ============================================================================= 21// 22 LED Ring / Stripe --------------------------------------------------------------------- 23#include 24 <FastLED.h> 25#define NUM_LEDS 24 // Number of LEDs in ring 26#define 27 LED_DATA_PIN 9 // Data Pin for control of LEDs in strip 1 28 29CRGB 30 leds[NUM_LEDS]; // create array for LED ring 31 32#define LED_HUE_STD 33 13 // STandarD HUE = "color" of LED; 0~red, 32~orange, 64~yellow 34#define 35 LED_SAT_STD 255 // STandarD SATuration = saturation of color 36 of LED; 0~neutral grey, 255~pure color 37#define LED_VAL_STD 100 38 39int LED_HUE 40 = LED_HUE_STD; // HUE used for FastLED depending on input conditions 41int 42 LED_SAT = LED_SAT_STD; // SAT used for FastLED depending on input 43 conditions 44int LED_VAL = LED_VAL_STD; // VAL used for FastLED 45 depending on input conditions 46 47// LED red/yellow/green ---------------------------------------------------------------------- 48#define 49 LED_RED_PIN 3 50#define LED_YELLOW_PIN 4 51#define LED_GREEN_PIN 5 52 53// Vibration 54 sensor ============================================================================= 55#define 56 VIB_SENS_PIN_1 A1 // Input from vibration sensor 1 57int VibRead_1; 58 59// 60 Other stuff ============================================================================= 61#define 62 LEDMode_PIN A3 63int trigLim = 100; // trigger limit for 64 vibration sensor 65int beatsCount = 0; // counts number 66 of beats (limits for red, yellow, green can be set below) 67 68int beatsRedLim 69 = 192; 70int beatsYellowLim = 384; 71int beatsGreenLim = 1536; 72 73int switchOnDelay 74 = 2; // time (ms) between switchin on subsequent LEDs 75 76/* 77 78 * Setup =================================================================================== 79 80 */ 81void setup() { 82 Serial.begin(9600); 83 FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, 84 NUM_LEDS); // setup LED ring 85 86 pinMode(LED_DATA_PIN, OUTPUT); 87 pinMode(LEDMode_PIN, 88 INPUT); 89 90 pinMode(LED_RED_PIN, OUTPUT); 91 pinMode(LED_YELLOW_PIN, OUTPUT); 92 93 pinMode(LED_GREEN_PIN, OUTPUT); 94 95 pinMode(VIB_SENS_PIN_1, INPUT); 96 97} 98/* 99 100 * End of Setup =================================================================================== 101 102 */ 103 104/* 105 * Main Loop =================================================================================== 106 107 */ 108 109void loop() { 110 LED_HUE = LED_HUE_STD; // HUE used 111 for FastLED depending on input conditions 112 LED_SAT = LED_SAT_STD; // 113 SAT used for FastLED depending on input conditions 114 LED_VAL = LED_VAL_STD; // 115 VAL used for FastLED depending on input conditions 116 117 // Wait until vibration 118 sensor detects something 119 VibRead_1 = 0; 120 while( VibRead_1 < trigLim ) { 121 122 VibRead_1 = analogRead(VIB_SENS_PIN_1); // VibRead_1 used as trigger as 123 well as determining brightness of LEDs 124//Serial.println("Waiting for input from 125 vibration sensor"); 126 } 127 128 beatsCount = beatsCount + 1; // 129 increase number of beats 130 // turn on red, yellow or green LED, depending on 131 number of total beats 132 if (beatsCount <= beatsYellowLim) { 133 digitalWrite(LED_RED_PIN, 134 HIGH); 135 } 136 if (beatsCount > beatsYellowLim && beatsCount < beatsGreenLim) 137 { 138 digitalWrite(LED_YELLOW_PIN, HIGH); 139 } 140 if (beatsCount > beatsGreenLim) 141 { 142 digitalWrite(LED_GREEN_PIN, HIGH); 143 } 144 145 LED_VAL = map(VibRead_1, 146 0, 1023, 0, 255); // derive brightness values for LEDs from magnitude of vibration 147/*Serial.println(); 148Serial.println(VibRead_1); 149Serial.println(LED_VAL); 150*/ 151 152/*Serial.print("Vib Sens 1: "); 153Serial.print(VibSens_1); 154Serial.print(" 155 Vib Read 1: "); 156Serial.println(VibRead_1); 157*/ 158 159 int LEDMode = analogRead(LEDMode_PIN); 160 // value used for selection of color pattern 161 162/*Serial.print("LEDMode: 163 "); 164Serial.println(LEDMode); 165*/ 166 167 // set LED HUE etc. depending on 168 input 169 if (0 < LEDMode && LEDMode < 250) { 170 LED_HUE = 2; 171 for (int 172 i=0; i<NUM_LEDS; i++) { 173 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 174 FastLED.show(); 175 176 delay(switchOnDelay); 177 } 178 } 179 if (250 < LEDMode && LEDMode < 180 500) { 181 LED_HUE = 80; 182 for (int i=0; i<NUM_LEDS; i++) { 183 leds[i]=CHSV(LED_HUE, 184 LED_SAT, LED_VAL); 185 FastLED.show(); 186 delay(switchOnDelay); 187 } 188 189 } 190 if (500 < LEDMode && LEDMode < 700) { 191 LED_HUE = 150; 192 for 193 (int i=0; i<NUM_LEDS; i++) { 194 leds[i]=CHSV(LED_HUE, LED_SAT, LED_VAL); 195 196 FastLED.show(); 197 delay(switchOnDelay); 198 } 199 } 200 if (700 201 < LEDMode && LEDMode < 1023) { 202 for (int i=0; i<NUM_LEDS; i++) { 203 leds[i]=CHSV(int(192/NUM_LEDS*i), 204 LED_SAT, LED_VAL); 205 FastLED.show(); 206 delay(switchOnDelay); 207 } 208 209 } 210 211 //Turn all LEDs OFF 212 digitalWrite(LED_RED_PIN, LOW); 213 digitalWrite(LED_YELLOW_PIN, 214 LOW); 215 digitalWrite(LED_GREEN_PIN, LOW); 216 for (int i=0; i<NUM_LEDS; i++) 217 { 218 LED_HUE = 0; 219 LED_SAT = 0; 220 LED_VAL = 0; 221 leds[i]=CHSV(LED_HUE, 222 LED_SAT, LED_VAL); 223 FastLED.show(); 224 delay(switchOnDelay); 225 } 226 227} 228/* 229 230 * End of Main Loop =================================================================================== 231 232 */ 233
Downloadable files
Schematics for Hit'n'Blink.
Schematics for Hit'n'Blink.
Schematics for Hit'n'Blink.
Schematics for Hit'n'Blink.
Comments