Components and supplies
Battery Holder, AA x 4
Rotary potentiometer (generic)
Arduino Nano R3
5 mm LED: Green
Piezo Pressure Sensor
5 mm LED: Red
5 mm LED: Yellow
LED ring 24 LEDs
Resistor 220 ohm
Tools and machines
Heat Shrinking Tube
Solder Wire, Lead Free
Soldering iron (generic)
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 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
Downloadable files
Schematics for Hit'n'Blink.
Schematics for Hit'n'Blink.
Comments
Only logged in users can leave comments
torstengeppert
0 Followers
•0 Projects
Table of contents
Intro
0
0