document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN 8
  4. #define NUM_LEDS 3
  5. CRGB leds[NUM_LEDS];
  6.  
  7. long valori[] = {0, 0, 0}; //array
  8.  
  9.  
  10.  
  11.  
  12. int fsrPin = A0; //fsr1
  13. int fsrPin1 = A2; //fsr2
  14. int fsrPin2 = A3; //fsr3
  15. int fsrReading; // the analog reading from the FSR resistor divider int LEDbrightness;
  16. int fsrReading1;
  17. int fsrReading2;
  18. int LEDbrightness;
  19. long sommavalori;
  20. int x;
  21.  
  22. void setup() {
  23. pinMode (LED_PIN, OUTPUT);
  24. pinMode (fsrPin, INPUT);
  25.  
  26. FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  27. Serial.begin(9600);
  28.  
  29. }
  30.  
  31.  
  32. void loop(void) {
  33.  
  34.  
  35. valori[0] = analogRead(fsrPin);
  36. valori[1] = analogRead(fsrPin1);
  37. valori[2] = analogRead(fsrPin2);
  38.  
  39.  
  40. // Serial.print("Valori: ");
  41. // Serial.print(valori[0]);
  42. // Serial.print(" ");
  43. // Serial.print(valori[1]);
  44. // Serial.print(" ");
  45. // Serial.println(valori[2]);
  46.  
  47. sommavalori= valori[0]+valori[1]+valori[2];
  48. fsrReading = (valori[0] * 100)/ sommavalori;
  49. fsrReading1 = (valori[1] * 100)/ sommavalori;
  50. fsrReading2 = (valori[2] * 100)/ sommavalori;
  51.  
  52. // Serial.print(fsrReading);
  53. // Serial.print(" ");
  54. // Serial.print(fsrReading1);
  55. // Serial.print(" ");
  56. // Serial.println(fsrReading2);
  57. // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
  58. if ((fsrReading>81)&&(fsrReading<101))
  59. {leds[0] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
  60.  
  61. else if ((fsrReading>45)&&(fsrReading<80)) {
  62. leds[0] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
  63.  
  64. }
  65. else if ((fsrReading>23)&&(fsrReading<44)) {
  66. leds[0] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
  67.  
  68. }
  69.  
  70.  
  71. else if ((fsrReading>0)&&(fsrReading<22)) {
  72. leds[0] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
  73.  
  74. } else if (fsrReading<= 0) {
  75. leds[0] = CRGB(255,255,255); //If there is no weight, then white
  76. }
  77.  
  78.  
  79. // fsr1
  80. if ((fsrReading1>81)&&(fsrReading1<101))
  81. {leds[1] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
  82.  
  83.  
  84. else if ((fsrReading1>45)&&(fsrReading1<80)) {
  85. leds[1] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
  86.  
  87. }
  88. else if ((fsrReading1>23)&&(fsrReading1<44)) {
  89. leds[1] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
  90.  
  91. }
  92.  
  93.  
  94. else if ((fsrReading1>0)&&(fsrReading1<22)) {
  95. leds[1] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
  96.  
  97.  
  98. }
  99.  
  100. else if (fsrReading1<= 0) {
  101. leds[1] = CRGB(255,255,255); //If there is no weight, then white
  102. }
  103.  
  104.  
  105.  
  106. // fsr2
  107. if ((fsrReading2>81)&&(fsrReading2<101))
  108. {leds[2] = CRGB(255, 0, 0); } //If higher than 81% and lower than 101%, then red
  109.  
  110.  
  111. else if ((fsrReading2>45)&&(fsrReading2<80)) {
  112. leds[2] = CRGB(255,102,0); //If higher than 45% and lower than 80%, then orange
  113.  
  114. }
  115. else if ((fsrReading2>23)&&(fsrReading2<44)) {
  116. leds[2] = CRGB(0, 255, 0); //If higher than 23% and lower than 44%, then green
  117.  
  118. }
  119.  
  120.  
  121. else if ((fsrReading2>0)&&(fsrReading2<22)) {
  122. leds[2] = CRGB(0, 0, 255); //If higher than 0% and lower than 22%, then blue
  123.  
  124.  
  125. }
  126. else if (fsrReading2<= 0) {
  127. leds[2] = CRGB(255,255,255); //If there is no weight, then white
  128. }
  129.  
  130.  
  131.  
  132.  
  133. FastLED.show();
  134. if ((fsrReading>23)&&(fsrReading<44) && (fsrReading1>23)&&(fsrReading1<44) && (fsrReading2>23)&&(fsrReading2<44)) {
  135. Serial.println("1");
  136. }
  137. delay(1000);
  138. }
');