ilteris kaplan blog

Archive of blog posts since 2005

April 5, 2008

Wiki

Building the first Prototype Box

#wiki

Building the first Prototype Box

The first prototype of the box is built. Everything was ok if we don’t count I have spent couple of hours until I figured out that two of the buttons are closed buttons unlike the rest. I changed them and ran the code and it worked. Pictures are hopefully be around tomorrow. I still need to add a reset function with a timer so that users can be able to press the latest mood again. Also, Mike suggested using patterns whiule displaying colors. It is not a bad idea at all, I will give it a shot after I figure out the database connection and all network stuff.

Class Response

Overall I got a positive response. Everyone’s main concern including me is hwo we can make people press this once and once only. With its current shape the box is welcoming users to press it multiple times. This makes my chances go low to get an accurate data over our emotions.

  • Couple of suggestions are: Getting this data as it is but not using it. Basically, building a layer system between the database and the php so that I can filter the garbage through timestamp values etc. I am not sure if this is in scope of my current webdev abilities. But Andy’s point was good in terms of the idea of solving the problem over the server and not locally.
  • Tom suggested to put up a indicator that tells us that we are sending data remotely. This might make users aware of the fact that this box is a logger and it is not a colorful box only.
  • Another suggestion is to use patterns with colors to clarify the emotions.

I might just go ahead and use an indicator of one single color instead of color transformations at this point. Actually thinking about it again, the box can still display some colors, but when someone interacting with it, e.g. someone press on it, it should just go into “processing this data to the server mode” and the user clearly should understand that it is connecting to server and sending this data. Once it is in this mode he/she shouldn’t bother pressing to another emotion again. At least for some time. This should be stated clearly in my box.

Code

The Arduino code is below:



// declare inputs

int sickBtn       = 2;
int calmBtn       = 3;
int sadBtn        = 13;
int angryBtn      = 12;
int energeticBtn  = 5; 
int happyBtn      = 6;
int lovedBtn      = 7;
int tiredBtn      = 8;

byte switchState  = 0; // the status which button is pressed.


// flags that checks if our button is called previously.
byte sickCalled, calmCalled, sadCalled, angryCalled;
byte energeticCalled, happyCalled, lovedCalled, tiredCalled;


// RGB PINS
int redPin    =  9; // RED LED 
int greenPin  = 10; // GREEN LED
int bluePin   = 11; // BLUE LED

// our generic value holders that we are going to pass functions.
int redVal, greenVal, blueVal;

void setup() {

 Serial.begin(19200); // using bluetooth at 19200 baudrate in order to serially connect.
 Serial.println("Hello World"); // just to make sure everything is alright.
 
 //set digital pins to input.
 pinMode(sickBtn,      INPUT);
 pinMode(calmBtn,      INPUT);
 pinMode(sadBtn,       INPUT);
 pinMode(angryBtn,     INPUT);
 pinMode(energeticBtn, INPUT);
 pinMode(happyBtn,     INPUT);
 pinMode(lovedBtn,     INPUT);
 pinMode(tiredBtn,     INPUT); 
 
 // Tricolor legs at PWM pins.
 pinMode(redPin,       OUTPUT);
 pinMode(greenPin,     OUTPUT);
 pinMode(bluePin,      OUTPUT);
 
}

void loop() {

 switchState  = checkPressed();  // this is giving the button that is pressed.

  
 if((switchState == 1) && (sickCalled == 0)) {
   Serial.println("sickCalled");
   goSick();
 } else if ((switchState == 2) && (calmCalled == 0)) {
   Serial.println("calmCalled");
   goCalm();
 } else if ((switchState == 3) && (sadCalled == 0)) {
   Serial.println("sadCalled");
   goSad();
 } else if ((switchState == 4) && (angryCalled == 0)) {
   Serial.println("angryCalled");
   goAngry();
 } else if ((switchState == 5) && (energeticCalled == 0)) {
   Serial.println("energeticCalled");
   goEnergetic();  
 } else if ((switchState == 6) && (happyCalled == 0)) {
   Serial.println("happyCalled");
   goHappy(); 
 } else if ((switchState == 7) && (lovedCalled == 0)) {
   Serial.println("lovedCalled");
   goLoved();  
 } else if ((switchState == 8) && (tiredCalled == 0)) {
   Serial.println("tiredCalled");
   goTired();
  }
  delay (10);
}





void goSick() {
   sickCalled      = 1;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    = 194;
  int greenDest  = 254;
  int blueDest   =  0;
  
  
  goZero(redDest, greenDest, blueDest);
  
  
}

void goCalm() {
   sickCalled      = 0;
   calmCalled      = 1;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    =  20;
  int greenDest  = 254;
  int blueDest   = 254;
  
  goZero(redDest, greenDest, blueDest);
  
  
}

void goSad() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 1;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    = 28;
  int greenDest  = 0;
  int blueDest   = 54;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goAngry() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 1;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    = 232;
  int greenDest  =   0;
  int blueDest   =  0;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goEnergetic() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 1;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    = 254;
  int greenDest  =  92;
  int blueDest   =   0;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goHappy() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 1;
   lovedCalled     = 0;
   tiredCalled     = 0;
  
  int redDest    = 254;
  int greenDest  = 254;
  int blueDest   =  32;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goLoved() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 1;
   tiredCalled     = 0;
  
  int redDest    = 254;
  int greenDest  =  8;
  int blueDest   =  88;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goTired() {
   sickCalled      = 0;
   calmCalled      = 0;
   sadCalled       = 0;
   angryCalled     = 0;
   energeticCalled = 0;
   happyCalled     = 0;
   lovedCalled     = 0;
   tiredCalled     = 1;
  
  int redDest    =  2;
  int greenDest  =  2;
  int blueDest   =  56;
  
  goZero(redDest, greenDest, blueDest);
  
  
}


void goZero(int destR, int destG, int destB) {

  int counter = 4;


  while((redVal + greenVal + blueVal) > counter + 1) {
    Serial.print("redVal: ");
    Serial.print(redVal);
    Serial.print("\t");
    Serial.print("greenVal: ");
    Serial.print(greenVal);
    Serial.print("\t");
    Serial.print("blueVal: ");
    Serial.println(blueVal);


    if(redVal   <= counter) { 
      redVal   = 1; 
    } 
    else { 
      redVal -= counter;   
    }
    if(greenVal <= counter) { 
      greenVal = 1; 
    } 
    else { 
      greenVal -= counter; 
    }
    if(blueVal  <= counter) { 
      blueVal  = 1; 
    } 
    else { 
      blueVal -= counter;  
    }

    analogWrite(redPin,    redVal);
    analogWrite(greenPin,  greenVal);
    analogWrite(bluePin,   blueVal);
 
  }

  goCurrent(destR, destG, destB);

  // if you go negatives with values they reverse like in a color wheel and go white.

}

void goCurrent(int destR, int destG, int destB) {
  int counter = 2;


  while(redVal+greenVal+blueVal < destR+destG+destB ) {
    Serial.print("redVal: ");
    Serial.print(redVal);
    Serial.print("\t");
    Serial.print("greenVal: ");
    Serial.print(greenVal);
    Serial.print("\t");
    Serial.print("blueVal: ");
    Serial.println(blueVal);



    if(redVal  >= destR) { 
      redVal   = destR; 
    } 
    else { 
      redVal += counter;   
    }

    if(greenVal  >= destG) { 
      greenVal   = destG; 
    } 
    else { 
      greenVal += counter;   
    }

    if(blueVal  >= destB) { 
      blueVal   = destB; 
    } 
    else { 
      blueVal += counter;   
    }


    analogWrite(redPin,    redVal); 
    analogWrite(greenPin,  greenVal);
    analogWrite(bluePin,   blueVal);
    
    
  }

  Serial.print("redVal: ");
    Serial.print(redVal);
    Serial.print("\t");
    Serial.print("greenVal: ");
    Serial.print(greenVal);
    Serial.print("\t");
    Serial.print("blueVal: ");
    Serial.println(blueVal);
}


byte checkPressed () {
 byte sick       = digitalRead(sickBtn     );
 byte calm       = digitalRead(calmBtn     );
 byte sad        = digitalRead(sadBtn      );
 byte angry      = digitalRead(angryBtn    );
 byte energetic  = digitalRead(energeticBtn);
 byte happy      = digitalRead(happyBtn    );
 byte loved      = digitalRead(lovedBtn    );
 byte tired      = digitalRead(tiredBtn    ); 
 
 if(sick      == 1) { return 1; }
 if(calm      == 1) { return 2; }
 if(sad       == 1) { return 3; }
 if(angry     == 1) { return 4; }
 if(energetic == 1) { return 5; }
 if(happy     == 1) { return 6; }
 if(loved     == 1) { return 7; }
 if(tired     == 1) { return 8; }
else {
  }
}



Continue Reading

Back to Archive