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.
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++;
}
}
<