#include <FastLED.h>
#define LED_PIN 8
#define NUM_LEDS 3
CRGB leds[NUM_LEDS];
long valori[] = {0, 0, 0}; //array
int fsrPin = A0; //fsr1
int fsrPin1 = A2; //fsr2
int fsrPin2 = A3; //fsr3
int fsrReading; // the analog reading from the FSR resistor divider int LEDbrightness;
int fsrReading1;
int fsrReading2;
int LEDbrightness;
long sommavalori;
int x;
void setup() {
pinMode (LED_PIN, OUTPUT);
pinMode (fsrPin, INPUT);
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
Serial.begin(9600);
}
void loop(void) {
valori[0] = analogRead(fsrPin);
valori[1] = analogRead(fsrPin1);
valori[2] = analogRead(fsrPin2);
// Serial.print("Valori: ");
// Serial.print(valori[0]);
// Serial.print(" ");
// Serial.print(valori[1]);
// Serial.print(" ");
// Serial.println(valori[2]);
sommavalori= valori[0]+valori[1]+valori[2];
fsrReading = (valori[0] * 100)/ sommavalori;
fsrReading1 = (valori[1] * 100)/ sommavalori;
fsrReading2 = (valori[2] * 100)/ sommavalori;
// Serial.print(fsrReading);
// Serial.print(" ");
// Serial.print(fsrReading1);
// Serial.print(" ");
// Serial.println(fsrReading2);
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
if ((fsrReading>81)&&(fsrReading<101))
{leds[0] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
else if ((fsrReading>45)&&(fsrReading<80)) {
leds[0] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
}
else if ((fsrReading>23)&&(fsrReading<44)) {
leds[0] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
}
else if ((fsrReading>0)&&(fsrReading<22)) {
leds[0] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
} else if (fsrReading<= 0) {
leds[0] = CRGB(255,255,255); //If there is no weight, then white
}
// fsr1
if ((fsrReading1>81)&&(fsrReading1<101))
{leds[1] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
else if ((fsrReading1>45)&&(fsrReading1<80)) {
leds[1] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
}
else if ((fsrReading1>23)&&(fsrReading1<44)) {
leds[1] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
}
else if ((fsrReading1>0)&&(fsrReading1<22)) {
leds[1] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
}
else if (fsrReading1<= 0) {
leds[1] = CRGB(255,255,255); //If there is no weight, then white
}
// fsr2
if ((fsrReading2>81)&&(fsrReading2<101))
{leds[2] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
else if ((fsrReading2>45)&&(fsrReading2<80)) {
leds[2] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
}
else if ((fsrReading2>23)&&(fsrReading2<44)) {
leds[2] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
}
else if ((fsrReading2>0)&&(fsrReading2<22)) {
leds[2] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
}
else if (fsrReading2<= 0) {
leds[2] = CRGB(255,255,255); //If there is no weight, then white
}
FastLED.show();
if ((fsrReading>23)&&(fsrReading<44) && (fsrReading1>23)&&(fsrReading1<44) && (fsrReading2>23)&&(fsrReading2<44)) {
Serial.println("1");
}
delay(1000);
}