This week, we combined the software switch we made last week with XBB to create a wireless communication device that utilizes both hardware and software.

We encountered some difficulties with getting the correct code and circuit, but after some troubleshooting, we discovered that the problem was in the initial stage of XCTU. We had forgotten to switch "MY" and "DL." Once we corrected this, the system ran smoothly.

Components:

Arduino Lilypad USB, soft switch, X-Bees, XBee Adapter, XCTU

Idea:

By integrating XBB into clothing and accessories, we can create a new way of communicating and sharing information, which may change the way we interact with our environment and with each other.

For example, we can make a jacket that uses XBB technology to display your current mood or emotional state.The jacket could change colors or patterns depending on your mood, allowing others to easily understand how you're feeling without even having to ask.This could be particularly useful in social situations where communication can be difficult or awkward.

Another possible application of XBB in wearable technology is in the field of sports and fitness. XBB technology could be integrated into athletic clothing, allowing athletes to track their performance and receive real-time feedback on their movements and technique. This could help athletes to improve their performance and avoid injuries.

Videos:

with soft switch

264_1677163871.mp4

with Processing

263_1677163820.mp4

Codes:

XBEE-A

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second in your serial port:
  mySerial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A5);
  // print out the value you read in your serial port:
  mySerial.println(sensorValue);
  delay(100);        // delay in between reads for stability
}

XBEE-B

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#define NUM_OF_VALUES_FROM_XBEE 1    /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/

int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

/** DO NOT REMOVE THESE **/
int tempValue = 0;
int valueIndex = 0;
int xbee_values[NUM_OF_VALUES_FROM_XBEE]; /** create an array to store the data from Processing**/
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  pinMode(9, OUTPUT);
  mySerial.begin(9600);
}
void loop() {
  getSerialData();
  xbee_values[0] = constrain(xbee_values[0], 0, 255);
//  xbee_values[0] = map(xbee_values[0], 0, 200, 0, 255);
  analogWrite(9, xbee_values[0]);
  if (xbee_values[0] > 100) {
   digitalWrite(led, HIGH); 
  }else{
    digitalWrite(led, LOW); 
    }
  Serial.println(xbee_values[0]);// print out the value you read:
  delay(1);  
  // set the brightness of pin 9:
//  analogWrite(led, brightness);
  // change the brightness for next time through the loop:
//  brightness = brightness + fadeAmount;
//
//  // reverse the direction of the fading at the ends of the fade:
//  if (brightness <= 0 || brightness >= 255) {
//    fadeAmount = -fadeAmount;
//  }
//  // wait for 30 milliseconds to see the dimming effect
//  delay(30);
}

//receive serial data from Processing
void getSerialData() {
  while (mySerial.available()) {
    char c = mySerial.read();
    //switch - case checks the value of the variable in the switch function
    //in this case, the char c, then runs one of the cases that fit the value of the variable
    //for more information, visit the reference page: <https://www.arduino.cc/en/Reference/SwitchCase>
    switch (c) {
      //if the char c from Processing is a number between 0 and 9
      case '0'...'9':
        //save the value of char c to tempValue
        //but simultaneously rearrange the existing values saved in tempValue
        //for the digits received through char c to remain coherent
        //if this does not make sense and would like to know more, send an email to me!
        tempValue = tempValue * 10 + c - '0';
        break;
      //if the char c from Processing is a comma
      //indicating that the following values of char c is for the next element in the values array
      case ',':
        xbee_values[valueIndex] = tempValue;
        //reset tempValue value
        tempValue = 0;
        //increment valuesIndex by 1
        valueIndex++;
        break;
      //if the char c from Processing is character 'n'
      //which signals that it is the end of data
      case '\\n':
        //save the tempValue
        //this will b the last element in the values array
        xbee_values[valueIndex] = tempValue;
        Serial.println(tempValue);
        //reset tempValue and valueIndex values
        //to clear out the values array for the next round of readings from Processing
        tempValue = 0;
        valueIndex = 0;
        break;
    }
  }
}

Processing