TUI HW2--
Emotion Displayer -- Done by Digital I/O with Arduino Board
I made a "heart" 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.
===
I took a short video for the heart, but I found difficulty while uploading it to the course website, so, please click here for the video: http://www.youtube.com/v/FZXWS876Y-0
(When uploading video here---
The selected file Sheng-Ying HW2.AVI can not be attached to this post,
because it is only possible to attach files with the following extensions:
jpg jpeg gif png txt html doc xls pdf ppt pps odt ods odp.
)
===
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;
}
}
Comments
Thanks for your comment and the lighter red LED
I just picked a styrofoam in good size and carved it into the cute little heart. After several trials, I finally made the wall of the heart very thin and still in the shape of a heart so that when I put the LEDs inside it the light can diffuse through it very well, except for the red LED. During this work I found that our original red LED is darker. Thank Kimiko for providing us lighter red LEDs!!!
GSI Comments
Great work! I like that you went beyond just creating direct input (commands like "make the lights red") to something that mapped between a feeling and a color. The use of adjectives and feelings (very happy, etc.) is also really good, because it makes the system much more expressive.
The diffuser is nice as well. It would be great to know what you made it out of, as it seemed to work well.