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

Two Parts: brushing teeth phase & dispensing floss phase...how to put them together....hmm

We've come far! We have two parts within this code for the two separate phases. We're now trying to figure out how to put the two sketches together, while also experimenting with boolean breakVariables! So far, not running the way we want it to but definitely seems close....


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

//this is for the speaker

int lightPin = 0;
int lightPin2 = 2;
int val = 0;
int val2 = 0;
int piezoPin = 8;
boolean breakVariable = true;



 #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 () {
  digitalWrite(piezoPin,LOW); //toothbrush covering it
  val = analogRead(lightPin);
  Serial.println(val);

val = analogRead(lightPin);
  Serial.println(val);  
  
 if (val >=6){
   digitalWrite (piezoPin, HIGH); //turn on
   
   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); 
  
  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 (2000); 

 val = analogRead(lightPin);
  Serial.println(val);

  if (val < 6) { //if toothbrush is put back 
  pos = 60; //dispense floss
  myservo.write(pos);
     
}
}
 //THIS PHASE ENDS THE BRUSHING OF THE TEETH
  
  //NOW INTO THE PHASE OF DISPENSING THE FLOSS
  
  val2 = analogRead(lightPin2);
  Serial.println(val2); 
   
  if (val2 < 6) { //container closed
  pos = 60; //position remains
  myservo.write(pos);
  
//  val2 = analogRead(lightPin2);
//  Serial.println(val2);
  
    if (val2 >= 6) { //if container opened
      pos = 5; //dispense coin
      myservo.write(pos);
      pos = 30; //bring servo back to center
      myservo.write(pos);
    }
 }
}


No comments:

Post a Comment