// Nano Glove // Includes easy transfer library which puts the data into an array // and includes a checksum for the recieving side for data verification. #include // Assigns an object for the Easy tansfer library EasyTransfer ET; // Data structure must be exactly the same on the recieving side // hen called by the recieving side. struct SEND_DATA_STRUCTURE { int ang1; int ang2; int ang3; int ang4; int ang5; }; // Names the group of data which contains the angle information // in an array. SEND_DATA_STRUCTURE mydata; // These define the analog pins of the Arduino Nano each flex sensor is attached to. int flexPin1 = A3; int flexPin2 = A4; int flexPin3 = A5; int flexPin4 = A6; int flexPin5 = A7; // These variables will be assigned to the analog reads from the flex sensor values. // These will be compared to the Openedf and Closedf. int finger1 = 0; int finger2 = 0; int finger3 = 0; int finger4 = 0; int finger5 = 0; // These are the variables which will later be assigned to the maximum finger travel // flex sensor reading. Temporarily assigned to zero. These values will be used to map // the servo values for a maximum. This will compensate for range changes if the voltage // to the sensors changes. int Openedf1 = 0; int Openedf2 = 0; int Openedf3 = 0; int Openedf4 = 0; int Openedf5 = 0; // These are the variables which will later be assigned to the minimum finger travel // flex sensor reading. These values will be used to map the servo values for a minimum. // This will compensate for range changes if the voltage to the sensors changes. int Closedf1; int Closedf2; int Closedf3; int Closedf4; int Closedf5; int ang1 = 0; int ang2 = 0; int ang3 = 0; int ang4 = 0; int ang5 = 0; int flex1 = 0; int flex2 = 0; int flex3 = 0; int flex4 = 0; int flex5 = 0; void setup() { // Beginning serial communication at 19200 baud rate Serial.begin(19200); //start the library, pass in the data details and the name of the serial port. ET.begin(details(mydata), &Serial); // Set each flex sensor pin to input. pinMode(flexPin1, INPUT); pinMode(flexPin2, INPUT); pinMode(flexPin3, INPUT); pinMode(flexPin4, INPUT); pinMode(flexPin5, INPUT); Closedf1 = analogRead(flexPin1); Closedf2 = analogRead(flexPin2); Closedf3 = analogRead(flexPin3); Closedf4 = analogRead(flexPin4); Closedf5 = analogRead(flexPin5); } void loop() { // Assigning analog read from flex sensors to variables flex1 = analogRead(flexPin1); flex2 = analogRead(flexPin2); flex3 = analogRead(flexPin3); flex4 = analogRead(flexPin4); flex5 = analogRead(flexPin5); // This ensures Openedf1 is a maximum and finger travel is maximized. Openedf1 is replaced with finger1 // if finger1 flex sensor reading is a maximum. The hand will need to be opened and closed a few times // for this to take effect. if (flex1 > Openedf1) { Openedf1 = flex1; } if (flex2 > Openedf2) { Openedf2 = flex2; } if (flex3 > Openedf3) { Openedf3 = flex3; } if (flex4 > Openedf4) { Openedf4 = flex4; } if (flex5 > Openedf5) { Openedf5 = flex5; } // This ensures Closedf1 is a minimum and finger travel is maximized. Openedf1 is replaced with finger1 // if finger1 flex sensor reading is a minimum. The hand will need to be opened and closed a few times // for this to take effect. if (flex1 < Closedf1) { Closedf1 = flex1; } if (flex2 < Closedf2) { Closedf2 = flex2; } if (flex3 < Closedf3) { Closedf3 = flex3; } if (flex4 < Closedf4) { Closedf4 = flex4; } if (flex5 < Closedf5) { Closedf5 = flex5; } // Using the map function to assign the analog read of the flex sensor voltage from the Closedf variables // which are the minimum of the range to the Openedf variables which are the maximum of the range. // Then assigns the angle data into the Easy transfer library variables. mydata.ang1 = map(flex1, Closedf1, Openedf1, 0, 180); mydata.ang2 = map(flex2, Closedf2, Openedf2, 0, 180); mydata.ang3 = map(flex3, Closedf3, Openedf3, 0, 180); mydata.ang4 = map(flex4, Closedf4, Openedf4, 0, 180); mydata.ang5 = map(flex5, Closedf5, Openedf5, 0, 180); // Sends the angle data to the recieving Xbee and Uno in the hand assembly. ET.sendData(); delay(20); }