As computing becomes more ubiquitous in our objects, designers need to be more aware of how to design meaningful interactions into electronically enhanced objects. At the University of Washington, a class of junior Interaction Design majors is exploring this question. These pages chronicle their efforts.

Tuesday, June 11, 2013

We're almost there!!!!!!!!!!

So our code is almost complete! We're getting a better idea on how/ when to use the "if" and the "While" and realized that they were not being used properly for the function we are looking to have in our last code. We've switched things around, rewrote much of the "Void Loop" and also organizing elements by providing our own names for different variables, such as "brushlight". 



#include <Servo.h>    
    Servo myservo;
    int pos = 30;

//this is for the speaker

int lightPin = 0;
int lightPin2 = 1;
int brushlight = 0;
int val2 = 0;
int piezoPin = 8;
int thresh = 




 #include "pitches.h"
int length = 15; // the number of notes
// notes in the melody:
int melody[] = {
  NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
  
int noteDurations[] = {
  4, 8, 8, 4,4,4,4,4 };
int tempo = 300; // this set up is for the 


void setup() {
 pinMode(piezoPin, OUTPUT);
Serial.begin(9600);

for (int thisNote = 0; thisNote < 8; thisNote++) {
   int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
    
   
      myservo.attach(9);
      Serial.begin(9600);
}
  }



void loop () 
{
  brushlight = analogRead(lightPin);
  Serial.println("brushlight");


if (brushlight >= thresh) 
{ //  toothbrush taken out 
     
     for (int thisNote = 0; thisNote < 8; thisNote++) 
     {
       int noteDuration = 1000/noteDurations[thisNote];
       tone(8, melody[thisNote],noteDuration);
       int pauseBetweenNotes = noteDuration * 1.30;
       delay(pauseBetweenNotes);
       noTone(8);
     }
     
    delay (3000); //brushing teeth
    
    for (int thisNote = 0; thisNote < 8; thisNote++) 
    {
       int noteDuration = 1000/noteDurations[thisNote];
       tone(8, melody[thisNote],noteDuration);
       int pauseBetweenNotes = noteDuration * 1.30;
       delay(pauseBetweenNotes);
       noTone(8);
    }
    
    brushlight = analogRead(lightPin);
    Serial.println("brushlight");
    
    while (brushlight >= thresh)  //checks as long as toothbrush is out 
     {
      brushlight = analogRead(lightPin);
      Serial.println("brushlight"); 
     } 
  // at this point, toothbrush is put back
  
    pos = 60; //dispense floss
    myservo.write(pos);
    pos = 30; //neutral pos
    myservo.write(pos);
    
    val2 = analogRead(lightPin2);
    Serial.println("val2");
    
    while (val2 < thresh) //container covered, 
    {
    val2 = analogRead(lightPin2);
    Serial.println("val2");  
    }
    // container is now opened 
    
    pos = 5; //dispense coin
    myservo.write(pos);
    pos = 30;
    myservo.write(pos);
  
 }//if

}


No comments:

Post a Comment