Updates from December, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • Yury Gitman 2:26 am on December 3, 2008 Permalink | Reply  

    antisocial cat_prototype 006 code iteration 

    So, yeah, I figured out what the problems were and finally made the servo work as the way I want! Hooray!
    When the toy detects me (using sensor), it would turn its head and stay at that position until it detects me again and turns its head.

    http://vimeo.com/moogaloop.swf?clip_id=2414067&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
    prototype 006 code iteration from maze on Vimeo.

    And here is the code:

    ———————————————————–

    #include <Servo.h>

    Servo myservo; //create servo object to control a servo
    int sensor = 0;  // analog pin used to connect the sensor
    int motorPin=11;
    int val;    // variable to read the value from the analog pin
    boolean status=0; //status of detecting
    int counter=0;

    void setup()
    {
      myservo.attach(11);
      myservo.setMaximumPulse(2200);
     
      Serial.begin(9600);           // set up Serial library at 9600 bps
      pinMode(sensor, INPUT);
      //pinMode(relay, OUTPUT);
      pinMode(motorPin, OUTPUT);
      myservo.setMaximumPulse(2000);
      myservo.setMinimumPulse(700);

      Serial.print("Ready\n");
    }//end of setup

    int getSensor() {
      val = analogRead(sensor);            // reads the value of the potentiometer (value between 0 and 1023)
      val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)

      val=max(val,5);
      val=min(val,180);

      return val;
    } //end of getSensor

    void myRefresh(int delayTime){
      for(int i=0; i < delayTime/20; i++){ //delay is the total ms delay we want, 20 is the delay per iteration of the loop 
          Servo::refresh(); 
          delay(20);
      }
    }

    int move0(){
      Serial.print("servo position 0\n");
      myservo.write(0);
      //Servo::refresh();
      myRefresh(100);
    }//end of move0

    int move90(){
      Serial.print("servo position 90\n");
      myservo.write(90);
      //Servo::refresh();
      myRefresh(100);
    }//end of move90

    int move180(){
      Serial.print("servo position 180\n");
      myservo.write(180);
      //Servo::refresh();
      myRefresh(100);
    }//end of move180

    void loop()
    {
        val=getSensor();
        Serial.println(val);
       
       
        if (val>20){
          if(status==0){
             move180();
             myRefresh(1000);                           // waits for the servo to get there
             counter++;
          }

          else if(status==1){
            move0();
            myRefresh(1000);
            counter++;
          }//end of else

        }//end of if
       
        if(counter%2!=0){
          status=1;
        }else{
        status=0;
        }

        //myservo.write(getSensor());
        //Serial.println(getSensor());
        //delay(15);

      Servo::refresh();
    }

    —————————————————————————–

    I defined a function myRefresh() to make sure the servo would be refreshed every 20ms.
    Then I added 3 moving functions with different angles.
    The tricky part was that how to make servo stop and turn to reverse direction when the sensor detects someone again. By using 2 variables counter and status, I made servo turn to position 180 when the counter is even and turn to position 0 when it is odd.

    In this week, I’ll try to put the prototype that I have so far into the body of my plush prototype.
    The focus of the testing this week will be:
    – redesign the character for prototyping (make it big enough to put all my electronics)
    – building/ sewing the plush toy
    – make the toy’s head move! Think about materials, the skeleton, connections… etc.

     
  • Yury Gitman 1:00 am on December 3, 2008 Permalink | Reply  

    12 Quack! 

    After a long fight with win bound chip and arduino and bubbles…, I finally heard it quack!

    http://vimeo.com/moogaloop.swf?clip_id=2413709&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
    Quack! from Hsiang Ju Hung on Vimeo.

    Here’s the code:
    // Input settings
    int analogPin = 3;   // ir sensor connected to analog pin 3
    int val = 0;         // variable to store the read value

    // Digital pin settings
    int aOut = 9;   // Play pin connected to digital pin 9

    // Variables
    int aVal = 0;   // Variables to store the input from the ir sensor

    int DEBUG = 1; // Set to 1 to turn on debugging output

    int average[100]; // Averaging Code setting
    byte counter = 0;

    void setup()
    {
      pinMode(aOut, OUTPUT);   // sets the pin as output

      if (DEBUG) {

        Serial.begin(9600);     // Open serial communication for reporting
      }
    }

    //Main program
    void loop(){
      val = analogRead(analogPin);

      //Averaging Code start
      average[counter] =  val;
      byte c;
      int total = 0;
      for(c = 0;c<100;c++){
        total += average[c];
      }
      int averaged = total / 100;
      Serial.println(averaged);
      counter = (counter + 1) % 100; //Averaging Code. modified from Dave Millis example

      if(val < 300){       
        analogWrite(aOut, 0);
        delay(1500);
        analogWrite(aOut, 255);
        delay(100);
      }
      else{                  
        analogWrite(aOut, 255);
      }
        if (DEBUG) {      // if we want to read the output
        DEBUG+=1;      
        if(DEBUG>100){  //print every hunderd loops
          DEBUG = 1;    // reset the counter
      Serial.print(val);
        }}
    }

    And here is the new win bound recorder which is smaller, more solid, and works as well as the old one. It sounds actually better because  I got a bigger speaker for it.
    Dscn0743

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel