const int ledPin1 = 12;
const int ledPin2 = 10;
const int ledPin3 = 11;
const int ledPin4 = 13;
const int ledPin5 = 26;
const int ledPin6 = 27;
const int ledPin7 = 28;
const int ledPin8 = 29;
unsigned long sensorSetupStartTime;
int pressureBaselineDeviation[8][6];
int currentReading;
int sensorMax[8][6] = {
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0}
};
void setup() {
Serial.begin(115200);
delay(1000);
while (!Serial) {
delay(100);
};
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
Serial.println("OK");
sensorSetup();
//digitalWrite(ledPin8, HIGH);
}
void sensorSetup()
{
int sensorValue;
for (int t = 0; t< 50; t++)
{
for (int j = 0; j<6; j++)
{
digitalWrite(j, HIGH);
for (int k = 0; k < 8; k++)
{
sensorValue = analogRead(k+1);
if (sensorValue > sensorMax[k][j])
{
sensorMax[k][j] = sensorValue;
}
}
digitalWrite(j-1, LOW);
}
}
}
void loop() {
for (int j = 0; j < 6; j++)
{
digitalWrite(j, HIGH);
for (int k = 14; k < 22; k++)
{
// measure of how much the reading changed from the baseline reading we took in the setup function
pressureBaselineDeviation[k][j] = analogRead(k+1) - sensorMax[k][j];
if ((k == 7) && (j == 5))
{
int pressureMaxRow = 0;
int pressureMaxCol = 0;
for( int kmax = 0; kmax < 8; kmax++)
{
for (int jmax = 0; jmax < 6; jmax++)
{
if (kmax > 0 || jmax > 0)
{
if (pressureBaselineDeviation[kmax][jmax] > pressureBaselineDeviation[pressureMaxRow][pressureMaxCol] )
{
pressureMaxRow = kmax;
pressureMaxCol = jmax;
}
}
}
}
if ((pressureMaxRow == 0) && (pressureMaxCol == 0))
{
if (pressureBaselineDeviation[0][0] > 20)
{
Serial.print(pressureMaxRow);
Serial.print(",");
Serial.print(pressureMaxCol);
Serial.print(",");
Serial.println(pressureBaselineDeviation[pressureMaxRow][pressureMaxCol]);
}
}
else
{
if (pressureBaselineDeviation[pressureMaxRow][pressureMaxCol] > 7)
{
Serial.print(pressureMaxRow);
Serial.print(",");
Serial.print(pressureMaxCol);
Serial.print(",");
Serial.println(pressureBaselineDeviation[pressureMaxRow][pressureMaxCol]);
}
}
}
}
digitalWrite(j, LOW);
}
delay(20);
}
void OnLed()
{
float a = 0;
float b = 0;
if (Serial.available() > 0)
{
}
if (a == 1)
{
if (b == 1)
{
digitalWrite(ledPin1, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin1, LOW);
}
}
if (a == 2)
{
if (b == 1)
{
digitalWrite(ledPin2, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin2, LOW);
}
}
if (a == 3)
{
if (b == 1)
{
digitalWrite(ledPin3, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin3, LOW);
}
}
if (a == 4)
{
if (b == 1)
{
digitalWrite(ledPin4, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin4, LOW);
}
}
if (a == 5)
{
if (b == 1)
{
//Serial.println("LED 5 ON");
digitalWrite(ledPin5, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin5, LOW);
}
}
if (a == 6)
{
if (b == 1)
{
digitalWrite(ledPin6, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin6, LOW);
}
}
if (a == 7)
{
if (b == 1)
{
digitalWrite(ledPin7, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin7, LOW);
}
}
if (a == 8)
{
if (b == 1)
{
digitalWrite(ledPin8, HIGH);
}
if (b == 0)
{
digitalWrite(ledPin8, LOW);
}
}
}