Pressure Glove Arduino Code

by rbatzer

int sensorPin = A4;
int sensorValue;
int internalLED = 13;
int LED1 = 5;
int LED2 = 6;
int LED3 = 9;
int LED4 = 10;
int val1 = 200;
int val2 = 110;
int val3 = 60;
int val4 = 30;
void setup() {
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH); //turns on the internal pull-up resistor
pinMode(internalLED, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
digitalWrite(internalLED, HIGH);
Serial.begin(9600);
}
void loop() {
sensorValue=analogRead(sensorPin);
Serial.println(sensorValue);
delay(100);
if (sensorValue < val1)
{
analogWrite(LED1, sensorValue*255/(val1-val2)-val2*255/(val1-val2));
if (sensorValue <val2)
{
digitalWrite(LED1, HIGH);
analogWrite(LED2, sensorValue*255/(val2-val3)-val3*255/(val2-val3));
if (sensorValue <val3)
{
digitalWrite(LED2, HIGH);
analogWrite(LED3, sensorValue*255/(val3-val4)-val4*255/(val3-val4));
if (sensorValue <val4)
{
digitalWrite(LED3, HIGH);
analogWrite(LED4, sensorValue*255/val4);
}
else
digitalWrite(LED4, LOW);
}
else
{
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}
else
{
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}
else {
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
}
}