Hi,
I have five LEDs wired individually to pins on an Arduino with 220 ohm resistors. For some reason, the LEDs connected to pins 2 and 3 are dimmer than the others. I tried re-arranging the LEDs to see if there was something wrong with them, but the LEDs connected to pins 2 and 3 are always dimmer. I also tried connecting to different pins on the Arduino. Below is an image of the connections. Any help would be greatly appreciated.
Edit: The sketch is below
#include <Wire.h>
#include "SparkFun_BMA400_Arduino_Library.h"
BMA400 accelerometer;
uint8_t i2cAddress = BMA400_I2C_ADDRESS_DEFAULT;
double y;
double prevY = 0;
int pos;
int n = 100;
int leds[5] = { 2, 3, 4, 5, 6 };
void setup()
{
Serial.begin(115200);
Wire.begin();
while(accelerometer.beginI2C(i2cAddress) != BMA400_OK)
{
Serial.println("Error: BMA400 not connected, check wiring and I2C address!");
delay(1000);
}
Serial.println("BMA400 connected!");
for (int i = 2; i <= 6; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop() {
for (int i = 0; i < n; i++) {
accelerometer.getSensorData();
y += accelerometer.data.accelY;
}
y /= n;
if (y - prevY > 0.03 || prevY - y > 0.03) {
if (y < 0) {
if (pos > 0)
pos--;
} else {
if (pos < 5)
pos++;
}
}
toggleLEDs(pos);
prevY = y;
Serial.println((String) pos + ", " + (String) y);
}
void toggleLEDs(int i) {
int ledOn;
switch (i) {
case 0: ledOn = 6; break;
case 1: ledOn = 5; break;
case 2: ledOn = 4; break;
case 3: ledOn = 3; break;
case 4: ledOn = 2; break;
default: ledOn = 0; break;
}
for (int i = 2; i <= 8; i++) {
if (i == ledOn) digitalWrite(ledOn, HIGH);
else digitalWrite(i, LOW);
}
}
