Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!


Revision of Emotion Displayer -- Done by Digital I/O w/ Arduino Board from Tue, 09/11/2007 - 02:05

Project Members: 
Sheng-Ying Pao

TUI HW2--

Emotion Displayer -- Done by Digital I/O w/ Arduino Board

I made a "heart" by myself as the diffuser for RGB LEDs.

Red heart represents you are happy.

Blue heart is for depressed feeling.

Green heart shows sth. makes you excited.

When you feel nervous, the heart will blink rapidly in different colors.

The stronger your feeling is, the lighter the LED will be.

 

My Code:

/* Aithne Sheng-Ying Pao
* TUI HW2
* Serial RGB LED
* ---------------
* I design the interface to express emotion!!! Ex. extremely happy, very depressed, somewhat excited, extremely nervous, and etc.
* Serial commands control the brightness of R,G,B LEDs
* Sep 11 2007
*/

//for a useful string comparison function, see the bottom of this file... stringsEqual()
#include <stdio.h>
#include <string.h>

char serInString[100]; // array that will hold the different bytes of the string. 100=100characters;
// -> you must state how long the array will be else it won't work properly
char colorCode;
char code1; // to record the first char of input string
int colorVal;

int redPin = 9; // Red LED, connected to digital pin 9
int greenPin = 10; // Green LED, connected to digital pin 10
int bluePin = 11; // Blue LED, connected to digital pin 11

int redValue = 000;
int greenValue = 000;
int blueValue = 000;

void setup() {
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
analogWrite(redPin, redValue); // turn off the light as initial state
analogWrite(greenPin, greenValue); //turn off the light as initial state
analogWrite(bluePin, blueValue); // turn off the light as initial state
Serial.println("enter your mood, please choose one from (extremely, very, and somewhat) and choose your mood from (happy, excited, depressed, and nervous) (eg. 'very happy') :");
}

void loop () {
//read the serial port and create a string out of what you read

readSerialString(serInString, 100);

mood(serInString);

//Erase anything left in the serial string, preparing it for the
//next loop
resetSerialString(serInString, 100);

delay(100); // wait a bit, for serial data
}

void resetSerialString (char *strArray, int length) {
for (int i = 0; i < length; i++) {
strArray[i] = '\0';
}
}

//read a string from the serial and store it in an array
//you must supply the array variable
void readSerialString (char *strArray, int maxLength) {
int i = 0;

if(!Serial.available()) {
return;
}
while (Serial.available() && i < maxLength) {
strArray[i] = Serial.read();
i++;
}
}

void mood(char *strArray) {
//read in the first character in the string
code1 = serInString[0];
int i = 0;
if(code1=='e'){ //extremely
colorVal=255;
i=10;

Serial.print("I feel extremely ");
}

if(code1=='v'){//very
colorVal=155;

i=5;
Serial.print("I feel very ");
}

if(code1=='s'){//somewhat
colorVal=55;

i=9;
Serial.print("I feel somewhat ");
}

colorCode=serInString[i];
if(colorCode == 'n') {
Serial.print("nervous!");
Serial.println();
int j=1;
while (j==1){
resetSerialString(serInString, 100);
readSerialString(serInString, 100);
if (serInString[0]!='\0'){
j=0;

analogWrite(bluePin, 000);
analogWrite(redPin, 000); // turn off the light
analogWrite(greenPin, 000);
mood(serInString);
}
else {
analogWrite(redPin, colorVal);
analogWrite(greenPin, 000); // turn off the light
analogWrite(bluePin, 000);
delay (500);
analogWrite(greenPin, colorVal);
analogWrite(redPin, 000); // turn off the light
analogWrite(bluePin, 000);
delay (500);
analogWrite(bluePin, colorVal);
analogWrite(redPin, 000); // turn off the light
analogWrite(greenPin, 000);
delay (500);
}
}
}

else if( colorCode == 'h' ) {
analogWrite(redPin, colorVal);
analogWrite(greenPin, 000); //turn off the light
analogWrite(bluePin, 000); // turn off the light
Serial.print("happy!");
Serial.println();

}

else if(colorCode == 'e') {
analogWrite(redPin, 000); //turn off the light
analogWrite(bluePin, 000); // turn off the light
analogWrite(greenPin, colorVal);
Serial.print("excited!");
Serial.println();
}

else if(colorCode == 'd') {
analogWrite(redPin, 000); //turn off the light
analogWrite(redPin, 000); // turn off the light
analogWrite(bluePin, colorVal);
Serial.print("depressed!");
Serial.println();
}

else if(colorCode == 'w') {
analogWrite(redPin, colorVal); //turn off the light
// analogWrite(redPin, 000); // turn off the light
analogWrite(bluePin, colorVal);
Serial.print("worried!");
Serial.println();
}

}

//compare two strings to see if they are equal
//compares the first 'numCharacters' characters of string1 and string2 to
//see if they are the same
//
//E.g. stringsEqual("hello","hello",5) => true
// stringsEqual("hello","helaabbnn",3) => true
// stringsEqual("hello","helaa",5) => false
boolean stringsEqual(char *string1, char *string2, int numCharacters) {
if (strncmp(string1, string2, numCharacters) == 0) {
return true;
} else {
return false;
}
}


Powered by Drupal - Design by Artinet