Tuesday 1 May 2012

Version 3.1 prototype development

These were the changes i needed to make to the prototype itself following the cognitive walk through.

1. Make it possible for the receiving user to provide feedback of some kind
2. Make the feedback for the sending message more gratifying i.e. a beep. Something which makes the teddy feel more 'interactive'.
3. Put the voice clip & MP3 in one clip (if both are used) as the MP3 naturally resets itself by playing the beginning of the most recent track, not the first song in the list.
4. Incorporate on/off switch so that the batteries aren't too badly drained (this can be done a little later).


The first thing i did was tweak the code so that the indicator light notified when the remote xBee had actually received the message, not when the button on the local xBee was pressed. This provides feedback that the communication is actually received, like a delivery report. 


This was done by adding a line of code to the relay xBee which said 'Send a notification when you receive a certain letter', and a line of code to the push button xbee which said 'turn the light on and off once when you receive notification that your message has been successfully received'. This was because according to Schneiderman's 8 golden rules I should offer informative feedback. I needed to add in notification that the message had been successfully received otherwise to give users some peace of mind knowing that their message had successfully got there. It also allows users to identify if the system is not working. In conjunction with feedback for when the message is sent, this provides a good error notifying mechanism which is Schneiderman's 5th rule 'Offer Simple Error Handling'. I can add error handling to the manual to say 'what to do if your message is successfully sent but you receive no feedback of it actually arriving'. 


The code changes are below


Arduino 1 (push button xBee)



if (Serial.read() == 'K'){
   
     digitalWrite(localINDICATOR, HIGH);
     delay(1000);  
      digitalWrite(localINDICATOR, LOW);
    delay(1000);  
    }

Arduino 2 


 if (val == 'D'){
     Serial.print('K');
      
      digitalWrite(relay, LOW); //TURN ON
 // delay(232000); i reduced the delay for developmental purposes-to see if everything worked correctly.
 delay(10000);
    digitalWrite(relay, HIGH); //TURN OFF
    delay(1000);
  
    } 




The next thing i did was to introduce a buzzer feedback for the user when the hands were touched together.  This would indicate that the message was successfully sent.


I used these guidelines for basic implementation: http://www.arduino.cc/en/Tutorial/PlayMelody and http://www.oomlout.com/oom.php/products/ardx/circ-06 and http://arduino.cc/en/Tutorial/Tone. As usual i tested the element seperately then incorporated it into my project.

This was my test code (developed mainly from http://arduino.cc/en/Tutorial/Tone). I had to create a separate pitches library, done by adding a new tab and renaming it. This will have to be added to the main code. I also moved the code from setup() to loop() so that it played repeatedly. I then added the pin as a global variable. The notes, their duration and delays are contained within arrays which would be useful when working with longer pieces, and also neaten up the code.


 #include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };
int piezoPin = 9;

void setup() {
  // iterate over the notes of the melody:

}

void loop() {
  for (int thisNote = 0; thisNote < 8; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(piezoPin, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(piezoPin);
  }
}

I want the sound to be a short bell sound. I searched http://www.freesound.org/ for inspiration. I decided on a fun, retro sounding clip.


After some experimentation i came up with a four tone, video game sounding clip which i will add and include.

There are clips of the code:
int melody[] = {  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3};
int noteDurations[] = {2, 4, 8, 2};
I had to change the loop at the bottom for 4 tones (I made this mistake on my first try without noticing and it made a horrible sound);
  for (int thisNote = 0; thisNote < 4; thisNote++) {

I also broke up the code into its own function called 'myTone' for modular integration.


void loop() {
myTone;
}

void myTone() { ...rest of code here...}

I noticed that it would be much simpler in fact if the tone code wasn't in a 'for' loop so save me having to write code to break out of it. I am going to restructure it. 

I also decided against having a multi-tonal indicator. It should only play once. 

I am using the new code below..

 #include "pitches.h"
int speakerPin = 9;
void setup() {
}

void loop() {
myTone();
}

void myTone() {
    tone(speakerPin, NOTE_C4,1000); //pin, not, duration
       delay(1300);
      noTone(speakerPin);     // stop the tone playing:  
}

I am incorporating this new code into the main code. 

This is the new code if (digitalRead(BUTTON) == LOW) {
        myTone(); 
 //   digitalWrite(localINDICATOR, HIGH); 
    Serial.print('D

This is the current system event architecture.



Still do to are: Task 1, 3 & 4. These will be completed in the next post. 


No comments:

Post a Comment