topical media & game development

talk show tell print

graphic-processing-algorithm-Ch11-p289-p289.pde / pde



  void setup(){
    pinMode(5,OUTPUT); //set the pin to output
    Serial.begin(9600); //open the serial to print
    Serial.print(“Ready”); //write a message
  }
  void loop(){
    int val = Serial.read(); //read the serial to see
    if(val>’0’ && val <= ‘9’){ //which key was pressed
      val = val - ‘0’; //convert the character to an integer
      val = val * (180/9); //9 divisions of 180 degrees
      Serial.print(“moving servo to “);
      Serial.print(val,DEC);
      Serial.println();
      for(int a=0; a<50; a++){
        int pulseWidth = (val*11)+500; // See the formula above
        digitalWrite(5,HIGH);
        delayMicroseconds(pulseWidth);
        digitalWrite(5,LOW);
        delay(20);
      }
    }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.