#include <Adafruit_NeoPixel.h>
// C++ code
//A1-->Extension
int pinledsA1 = 13;
int numledsA1 = 15;
Adafruit_NeoPixel stripA1 = Adafruit_NeoPixel(numledsA1, pinledsA1, NEO_GRB + NEO_KHZ800);
int pinInputA1 = A1;
int minvalueA1 = 0;
int groupsleds= 3;
/*
float firstcut = (numledsA1/groupsleds);
float secondcut = (numledsA1-numledsA1/groupsleds);
*/
void setup()
{
stripA1.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
Serial.begin(9600);
pinMode(pinInputA1, INPUT);
}
void loop(){
setlimits();
LEDBUILTIN ();
}
float floatmap(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
void setlimits(){
int firstcut=0;
int secondcut=0;
if(firstcut<1 && secondcut<1){
//Input voltage 0 to 5 volts at an analog pin(A1-A5) gives value read at the pin of 0 to 1023.
int InputA1 = analogRead(pinInputA1);
float mapA1 = floatmap(InputA1, 0, 1023, 0, numledsA1);
Serial.print("Analog: "); Serial.print(InputA1);
Serial.print(", InputA1: "); Serial.println(mapA1);
Serial.println("Ralaja el brazo:5segons ");
delay(2000);
const float firstcut=mapA1;/////
delay(3000);
Serial.println("Fuerza maxima brazo:5segons ");
const float secondcut=mapA1;/////
Serial.print(firstcut);/////
}
}
void LEDBUILTIN (){
stripA1.clear();
int InputA1 = analogRead(pinInputA1);
float mapA1 = floatmap(InputA1, 0, 1023, 0, numledsA1);
for (int A1=0; A1 < mapA1; A1++)
{
for (int a=0;a < firstcut; a++)
{
stripA1.setPixelColor(a,stripA1.Color(0,255,0));
}
for (int a=firstcut;a < secondcut; a++)
{
stripA1.setPixelColor(a,stripA1.Color(255,255,0));
}
for (int a=secondcut;a < numledsA1; a++)
{
stripA1.setPixelColor(a,stripA1.Color(255,0,0));
}
}
for (int e=mapA1; e < numledsA1; e++)
{
stripA1.setPixelColor(e, stripA1.Color(0, 0, 0));
}
stripA1.show();
}