processing to picaxe 18m2

jinx

Senior Member
hi all,
I,ve started playing around with processing http://processing.org/ found this sketch processing on LMR that lets you control a servo or even leds , heres a link http://letsmakerobots.com/node/21878to" more on how the processing works".
If you gonna try this you need processing 1.5.1 later version gave me grief setting up serial on a 64 bit machine

here's the picaxe code that recieves the serial data to control the servo's:
Code:
#Picaxe 18m2
#No_Data
#com 1

symbol analogvalue1 = b0
symbol analogvalue2 = b1
symbol servoport0   = b.4
symbol servoport1   = b.5





symbol base = w10 
symbol tilt = w11

init:
      disconnect
      servo servoport0, 150
      servo servoport1, 150
      
      
      pause 30
      
do
    serrxd (13), b0,b1,b3 
   

    if analogvalue1 <> base then
    servopos servoport0, analogvalue1
     let base = analogvalue1
     endif
     
    if analogvalue2 <> tilt then
    servopos servoport1, analogvalue2
     let tilt = analogvalue2
      endif
    
    loop
the code is what i normally use a 10k pot that why the symbol analogvalue but this time i place the b0,b1 into the analogvalue which is recieved serial it's rough but it works.

and here' the sketch code for processing:
Code:
import processing.serial.*;
Serial port;

sliderV sV1, sV2, sV3;

color cor;

void setup() {
  size(500, 500);

println("Available serial ports:");
println(Serial.list());

// check on the output monitor wich port is available on your machine
  port = new Serial(this,"COM1", 4800);

// create 3 instances of the sliderV class
  sV1 = new sliderV(100, 100, 90, 255, #FF0000);
  sV2 = new sliderV(200, 100, 90, 255, #03FF00);
  sV3 = new sliderV(300, 100, 90, 255, #009BFF);
}

void draw() {
  background(0);

  sV1.render();
  sV2.render();
  sV3.render();

// send sync character
// send the desired value
 port.write(13);
  delay (10);
  port.write(sV1.p);
  delay (10);
  port.write(sV2.p);
  delay (10);
  port.write(sV3.p);
  delay (10);
  
  println (sV1.p +" "+sV2.p +" "+sV3.p);
}

/* 
Slider Class - www.guilhermemartins.net
based on www.anthonymattox.com slider class
*/
class sliderV {
int x, y, w, h, p;
  color cor;
boolean slide;

  sliderV (int _x, int _y, int _w, int _h, color _cor) {
    x = _x;
    y = _y;
    w = _w;
    h = _h;
    p = 150;
    cor = _cor;
    slide = true;
  }

void render() {
    fill(cor);
    rect(x-1, y-4, w, h+10);
    noStroke();
    fill(0);
    rect(x, h-p+y-5, w-2, 13);
    fill(255);
    text(p, x+2, h-p+y+6);

    if (slide==true && mousePressed==true && mouseX<x+w && mouseX>x){
      if ((mouseY<=y+h+150) && (mouseY>=y-150)) {
        p = h-(mouseY-y);
if (p<0) {
          p=0;
        }
else if (p>h) {
          p=h;
        }
      }
    }
  }
}
here.s a link to a quick vid:http://www.youtube.com/watch?v=B4f_BQ1Dntk&feature=plcp
 
Top