Hey Guys
I'm doing a Year 12 D&T Major work this year. I made a drum kit and have put LED strips and sensors inside each drum. The idea is that each drum lights up in accordance to how hard I hit it. The entire circuit is built all I need to do is program my Arduino ATmega1280 to control it all.
So far I have a code that, when the sensor is triggered, the lights flash on in one drum. But that is all I can do. I can't seem to make a code that will control all four drums. All the drums will have the same function and so it is probably an easy fix but I'm only a novice at Arduino code. Any help would be greatly appreciated.
The single drum code I have is:
//This code assumes the largest value you will get from a sensor is 55, anything larger is assumed as 55
int val, brightness=2; //=Sensor Pin--Needed integers for sensor and brightness
const int threshold=0, highestval=150; //Constant integer for the threshold of the drum input sensors.
void setup()
{
pinMode(3,OUTPUT); //LED Pin
analogWrite(3,2); //LED Pin, Sensor Pin
}
void loop()
{
val = analogRead(2); //Sensor Pin--Read in from sensor
if (val>threshold)
{
brightness = val * (255/highestval); //Multiply sensor input number by scaling factor
if(brightness >255) //Check the values is not greater than maximum analog amount
{
brightness = 255; //set to analog maximum amount
}
}
if(brightness>1) //Check number in brightness
{
analogWrite(3,brightness); // LED Pin--If the sensor reads something, turn on LED
brightness = brightness - 5;
}
else
{
analogWrite(3,0); // LED Pin, 0--if nothing is happening, turn LED off
}
delay(10);
}
Let me know what you think
Thanks