Last active
December 26, 2015 17:39
-
-
Save BorisKourt/7188970 to your computer and use it in GitHub Desktop.
Arduino sample for http://boriskourt.com/2013/10/27/gesture-logging-garment/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
leftSide - 0 | |
leftArm - 1 | |
leftNeck - 2 | |
rightSide - 3 | |
rightArm - 4 | |
rightNeck - 5 | |
*/ | |
int difference = 0; | |
long previousSensorRead = 0; | |
long intervalSensorRead = 10; | |
int pin[] = {A0,A1,A2,A3,A4,A5}; | |
int val[] = {0,0,0,0,0,0}; | |
int pre[] = {0,0,0,0,0,0}; | |
int var[] = {400,400,400,400,400,400}; | |
int tem[] = {0,0,0,0,0,0}; | |
int* data[5]; | |
void setup() { | |
data[0] = pin; | |
data[1] = val; | |
data[2] = pre; | |
data[3] = var; | |
data[4] = tem; | |
Serial.begin(9600); | |
Serial1.begin(9600); | |
} | |
void loop() { | |
while (Serial.available() > 0) { | |
data[4][0] = Serial.parseInt(); | |
data[4][1] = Serial.parseInt(); | |
data[4][2] = Serial.parseInt(); | |
data[4][3] = Serial.parseInt(); | |
data[4][4] = Serial.parseInt(); | |
data[4][5] = Serial.parseInt(); | |
if (Serial.read() == '\n') { | |
data[3][0] = data[4][0]; | |
data[3][1] = data[4][1]; | |
data[3][2] = data[4][2]; | |
data[3][3] = data[4][3]; | |
data[3][4] = data[4][4]; | |
data[3][5] = data[4][5]; | |
for(int i=0; i<6; i++){ | |
Serial.println(data[3][i]); | |
} | |
} | |
} | |
unsigned long currentMillis = millis(); | |
if (currentMillis - previousSensorRead > intervalSensorRead) { | |
previousSensorRead = currentMillis; | |
data[1][0] = analogRead(data[0][0]); | |
data[1][1] = analogRead(data[0][1]); | |
data[1][2] = analogRead(data[0][2]); | |
data[1][3] = analogRead(data[0][3]); | |
data[1][4] = analogRead(data[0][4]); | |
data[1][5] = analogRead(data[0][5]); | |
} | |
for(int i=0; i<6; i++){ | |
difference = data[1][i] - data[2][i]; | |
if (abs(difference) >= data[3][i]) { | |
data[2][i] = data[1][i]; | |
logOut(i,currentMillis); | |
} | |
} | |
} | |
void logOut(int iD, long timeStamp) { | |
// Output to VIEWER: | |
Serial.println("The ID:"); | |
Serial.println(iD); | |
Serial.println("The Value:"); | |
Serial.println(data[2][iD]); | |
// Output to LOGGER: | |
Serial1.print(iD); | |
Serial1.print(","); | |
Serial1.print(timeStamp); | |
Serial1.print(","); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment