Using the following code I get normal sensor readings from the Piezo Sensor when tapped however as soon as I uncomment out the LED related code the Piezo Sensors stop getting correct readings.
If I run the code to turn on the LEDs then run it again with the LED code commented out leaving the LEDs illuminated I still get interference issues so I have ruled out some sort of electrical interference. Not sure if it is maybe an issue with pins.
#include "FastLED.h"
#define NUM_LEDS 18
#define BRIGHTNESS 5
#define NUM_TARGETS 3
struct target {
int targetID;
int sensorPin;
int sensorReading;
int threshold;
bool isHit;
};
target target1;
CRGB target1LEDS[NUM_LEDS];
CLEDController *targetLEDS[NUM_TARGETS];
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
Serial.println("START");
target1.targetID = 1;
target1.threshold = 10;
target1.sensorPin = A5;
// targetLEDS[0] = &FastLED.addLeds<NEOPIXEL, 11>(target1LEDS, NUM_LEDS); // Far left
// for (int l = 0; l <= NUM_LEDS; l += 2) {
// target1LEDS[l] = CRGB(0, 0, 0);
// }
// targetLEDS[0]->showLeds(BRIGHTNESS);
// for (int l = 0; l <= NUM_LEDS; l += 2) {
// target1LEDS[l] = CRGB(0, 0, 255);
// }
// targetLEDS[0]->showLeds(BRIGHTNESS);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
//read the sensor and store it in the variable sensorReading:
target1.sensorReading = analogRead(target1.sensorPin);
// if the sensor reading is greater than the threshold:
if (target1.sensorReading > target1.threshold) {
String stringOne = "Target 1 reading: ";
String stringThree = stringOne + target1.sensorReading;
Serial.println(stringThree);
}
}

