Hi y'all!
We've got a problem with some leds that wont light up as theyre supposed to.
We can tell theyre on but the are very weak. We've already tested all the electronics,
theyre fine and the leds are working with other codes.
The idea is to light up one led at a time every time someone has knocked a sertain amount of times at the knock sensor (piezo).
The led at pin 5 starts to light up after 10 knocks. But when the time comes to led pin 6 and 7 they are super weak.
Could someone please have a look at our code?
int knockPin = 3; //pin for incoming knock sensor
int ledPins[]= {5,6,7,8,9,10,11,12,13};
int ledPin = 5;
int ledCount = 14;
int knockVal;
int countKnock=0;
int mappedVal;
void setup()
{
Serial.begin(9600);
for(int i=5; i< ledCount; i++)
{
pinMode(ledPins[i],OUTPUT);
}
}
void loop()
{
knockVal = analogRead(knockPin);
mappedVal = map(knockVal,0,1023,1,10);//remap knockVal to a scale of 1-10 instead
if(mappedVal <=8) //every knock, increase countKnock with +1
{
countKnock +=1;
Serial.println(countKnock);
Serial.print("ledpin: ");
Serial.println(ledPin);
delay(80);
}
//when countKnock reaches 10 light the first led, and so on..
if(countKnock >= 10 && countKnock <20)
{
digitalWrite(5,HIGH);
}
if(countKnock >= 20 && countKnock <28)
{
digitalWrite(6,HIGH);
}
if(countKnock >= 28 && countKnock <36)
{
digitalWrite(7,HIGH);
digitalWrite(5,LOW);
}
}