So I've made a drumkit, and I've installed RGB leds and a series of white leds in each pad. Each pad connects to my arduino-based board, Ardweeny, via Cat6 cable. Each output on the ardweeny turns on a mosfet, which turns on the LED string. There are 5 leds per color, and 25 white LEDs right now, there will be more later.
Here is the current script:
//Pin Numbers
const int ledred = 0;
const int ledgreen = 1;
const int ledblue = 2;
const int ledOr = 3;
const int ledw = 4;
const int ledOg = 5;
const int ledYr = 6;
const int ledYg = 9;
//Analog Inputs
const int Ar = 5;
const int Ag = 4;
const int Ab = 3;
const int Ao = 1;
const int Ay = 2;
//Analog readings
int ArVal = 0;
int AgVal = 0;
int AbVal = 0;
int AoVal = 0;
int AyVal = 0;
int wcount = 0;
int wcount2 = 0;
int threshold = 230;
void setup() {
pinMode(ledred, OUTPUT);
pinMode(ledgreen, OUTPUT);
pinMode(ledblue, OUTPUT);
pinMode(ledw, OUTPUT);
//all Leds off
digitalWrite(ledred, LOW);
digitalWrite(ledgreen, LOW);
digitalWrite(ledblue, LOW);
digitalWrite(ledw, LOW);
analogWrite(ledOr, 0);
analogWrite(ledOg, 0);
analogWrite(ledYr, 0);
analogWrite(ledYg, 0);
}
void loop() {
//Read the inputs and divide it by 4
//so its between 0 and 255
ArVal = analogRead(Ar) / 4;
AgVal = analogRead(Ag) / 4;
AbVal = analogRead(Ab) / 4;
AoVal = analogRead(Ao) / 4;
AyVal = analogRead(Ay) / 4;
//Turn on the Leds if they're triggered
if (ArVal >= (threshold - 20)) {
digitalWrite(ledred, HIGH);
wcount++;
} else {
digitalWrite(ledred, LOW);
}
if (AgVal >= threshold) {
digitalWrite(ledgreen, HIGH);
wcount++;
} else {
digitalWrite(ledgreen, LOW);
}
if (AbVal >= threshold) {
digitalWrite(ledblue, HIGH);
wcount++;
} else {
digitalWrite(ledblue, LOW);
}
if (AoVal >= threshold) {
wcount++;
analogWrite(ledOr, 250); //Check orange and yellow vals
analogWrite(ledOg, 40);
} else {
analogWrite(ledOr, 0);
analogWrite(ledOg, 0);
}
if (AyVal >= threshold) {
wcount++;
analogWrite(ledYr, 250);
analogWrite(ledYg, 210);
} else {
analogWrite(ledYr, 0);
analogWrite(ledYg, 0);
}
//Every Xth hit, white turns on.
if (wcount >= 112) {
digitalWrite(ledw, HIGH);
wcount2++;
}
if (wcount2 >= 20) {
digitalWrite(ledw, LOW);
wcount = 0;
wcount2 = 0;
}
}
It reads the input, checks it against a threshold value, and turns the LED on if its above the threshold. If not, it turns it off. While above the threshold, it adds to a count which turns the white leds after a time. Which is just a cheap way of having them turn on every x hits.. It all worked fine on the test bench, but now with everything hooked up the white is not turning on as often as it should be, and after a few seconds of hitting the piezos, all the LEDs come on. The LEDs don't come on full tho, the yellow LED still shows up yellow(as far as I remember, tested last night). And there is a flicker on the white leds. It all works again for a little bit after hitting the reset button.
Is there a problem with my script, or is it possible that the analog input readings are being flooded somehow? Too much input at one time? I followed the Knock tutorial and have a 1M resistor in parallel with each piezo before connecting to the analog input. Perhaps the resistor isnt enough and I'm overloading the inputs. I'm also powering it by an old computer PSU, and I never got around to attaching a power resistor to keep a steady draw on the 5v rail, so that may be messing with the power.