SHARE
TWEET

Untitled

a guest Jul 23rd, 2014 3,701 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Controll servo on arduino
  2.  
  3. import processing.serial.*;
  4.  
  5. final int PAGE_UP=33;
  6. final int PAGE_DOWN=34;
  7. final int HOME=36;
  8. final int END=35;
  9.  
  10. Serial myPort;
  11. int angle=90;
  12.  
  13. void setup(){
  14.   size(640,480);
  15.   printArray(Serial.list());
  16.   String portName = Serial.list()[0];
  17.   myPort = new Serial(this, portName, 9600);
  18.   myPort.write(angle);
  19.   textSize(64);
  20.   textAlign(CENTER, CENTER);
  21. }
  22.  
  23. void draw(){
  24.   clear();
  25.   fill(255);
  26.   text(angle, 320, 240);
  27.   fill(0,255,0);
  28.   text("savinyurii.ru/DIY",320 ,32);
  29. }
  30.  
  31. void keyPressed() {
  32.   if(key==CODED) {
  33.     println(keyCode);
  34.     switch(keyCode){
  35.       case LEFT: angle--; break;
  36.       case RIGHT: angle++; break;
  37.       case UP: angle=90; break;
  38.       case PAGE_UP: angle+=10; break;
  39.       case PAGE_DOWN: angle-=10; break;
  40.       case HOME: angle=0; break;
  41.       case END: angle=180; break;
  42.     }
  43.     if(angle<0) angle=180;
  44.     if(angle>180) angle=0;
  45.      myPort.write(angle);
  46.      delay(20);
  47.   }
  48. }
RAW Paste Data
Top