Not to sure what is wrong with the code, it is reading the FSR values fine but for some reason it is not changing the colour of the LED. The LEDs I have are Piranha LED/RGB.
/* project 1 - analog in/analog out */
int sensPin = 2; // set the touch sensor (analog) input pin on Arduino
int bPin = 9; // select the pin for the RGB LED & LED array
int gPin = 10;
int rPin = 11;
int val = 0; // variable to store the value coming from the sensors
int B = 0; // variables for output
int G = 0;
int R = 0;
int inB = 0; //variables to prevent the code from being super buggy
int inG = 0;
int inR = 0;
void setup() {
pinMode(bPin, OUTPUT); // declare the led pins as OUTPUT
pinMode(gPin, OUTPUT);
pinMode(rPin, OUTPUT);
Serial.begin(9600); // diagnostic printout
}
void loop() {
val = analogRead(sensPin); // read the value from the sensor, set to diagnostic variable
if(inB <= 340) // BLUE LED
B = 0;
if(inB > 340 && inB <= 510)
B = map(inB, 341, 510, 0, 255);
if(inB > 510 && inB <= 850)
B = 255;
if(inB > 850)
B = map(inB, 851, 1023, 255, 0);
if(inG <= 170) // GREEN LED
G = map(inG, 0, 170, 0, 255);
if(inG > 170 && inG <= 510)
G = 255;
if(inG > 510 && inG <= 680)
G = map(inG, 511, 680, 255, 0);
if(inG > 680)
G = 0;
if(inR <= 170) // RED LED
R = 255;
if(inR > 170 && inR <= 340)
R = map(inR, 171, 340, 255, 0);
if(inR > 340 && inR <= 680)
R = 0;
if(inR > 680 && inR <= 850)
R = map(inR, 681, 850, 0, 255);
if(inR > 850)
R = 255;
analogWrite(bPin, B); // output RGB values to RGB pins
analogWrite(gPin, G);
analogWrite(rPin, R);
Serial.println(val); //diagnostic printout
}