0% found this document useful (0 votes)
10 views

Code for Operation

The document contains an Arduino sketch that utilizes the SoftwareSerial library to read data from flex sensors and an accelerometer. It processes the sensor readings to determine specific gestures and outputs corresponding messages via serial communication. The code includes various conditional statements to categorize the gestures into predefined commands based on the sensor values.

Uploaded by

kodalt658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Code for Operation

The document contains an Arduino sketch that utilizes the SoftwareSerial library to read data from flex sensors and an accelerometer. It processes the sensor readings to determine specific gestures and outputs corresponding messages via serial communication. The code includes various conditional statements to categorize the gestures into predefined commands based on the sensor values.

Uploaded by

kodalt658
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <SoftwareSerial.

h>
SoftwareSerial mySerial(2, 3); // RX, TX

const int flex1 = A0;


const int flex2 = A1;
const int flex3 = A2;
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A4; // y-axis
const int zpin = A5; // z-axis (only on 3-axis models)

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
mySerial.begin(9600);
delay(15000);
}

void loop() {
// put your main code here, to run repeatedly:
int x = analogRead(xpin);
delay(50);

int y = analogRead(ypin);
delay(50);

int z = analogRead(zpin);
delay(50);
int thumb;
int pointer;
int middle;
int nomx;
int nomy;
int nomz;

thumb = analogRead(flex1);
pointer = analogRead(flex2);
middle = analogRead(flex3);
nomx = x-265;
nomy = y-253;
nomz = z-323;

Serial.print(thumb);
Serial.print("\ ");
Serial.print(pointer);
Serial.print("\ ");
Serial.print(middle);
Serial.print("\ ");
Serial.print(nomx);
Serial.print("\ ");
Serial.print(nomy);
Serial.print("\ ");
Serial.print(nomz);
Serial.print("\
");
Serial.println("");
delay(500);
//group1
if ((thumb > 175) && (thumb < 210) && (pointer > 210) && (pointer < 235) &&
(nomy > 75) && (nomy < 95)) {
mySerial.print("LOOK FORWARD");
}
else if ((thumb > 175) && (thumb < 200) && (pointer > 210) && (pointer < 235)
&& (nomy > 160) && (nomy < 175)) {
mySerial.print("LOOK DOWN");
}
else if ((thumb > 175) && (thumb < 200) && (pointer > 210) && (pointer <
230)&& (nomy > 20) && (nomy < 35)) {
mySerial.print("LOOK UP");
}

//group2
else if ((thumb > 160) && (thumb < 195) &&(pointer > 160) && (pointer < 200)
&& (nomy > 28) && (nomy < 43)) {
mySerial.print("OKAY");
}
else if ((thumb > 190) && (thumb < 210) && (pointer > 180) && (pointer < 200)
&& (nomy > 160) && (nomy < 180)) {
mySerial.print("HOLD");
}
else if ((thumb > 160) && (thumb < 200) &&(pointer > 160) && (pointer < 190)
&& (nomy > 60) && (nomy < 75)) {
mySerial.print("PRONTO");
}

//group3
else if ((thumb > 230) && (thumb < 250) && (pointer > 150) && (pointer < 180)
&& (nomy >80) && (nomy < 100)) {
mySerial.print("CALL ME");
}
else if ((thumb > 230) && (thumb < 250) && (pointer > 150) && (pointer < 180)
&& (nomy >105) && (nomy < 125)) {
mySerial.print("THUMBS DOWN");
}
else if ((thumb > 230) && (thumb < 250) && (pointer > 150) && (pointer < 189)
&& (nomy >58) && (nomy < 70)) {
mySerial.print("I LOVE YOU");
}
else if ((thumb > 230) && (thumb < 250) && (pointer > 220) && (pointer < 235)
&& (nomy > 80) && (nomy < 105)) {
mySerial.print("GIVE ME");
}
else if ((thumb > 175) && (thumb < 195) && (pointer > 170) && (pointer < 190)
&& (nomy > 90) && (nomy < 110)) {
mySerial.print("GIVE ME SOME");
}
else{
mySerial.print("...");
}
}

You might also like