Loading...
Logo
Processing Forum
luxxnatura's Profile
7 Posts
7 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi all,
    I'm working on a project using real-time data and I'm a bit confused with how to do this exactly.  I'll be using an SSH authentication process at their request, and as I understand it, after sending them my public part of the key, I can connect to their server via Terminal (os x).  Once I've successfully logged on via Terminal, in my Processing code I'm wondering how to say "look to port number 22 (default SCP port), get latest file from this directory".  Is this simply using the Serial object (Serial =  new Serial(this, Serial.list()[22], 9600)), then specify the file path (with a bit of extra stuff around grabbing the latest file)?

    Also, I am wondering if I can setup the initial login in Processing and bypass Terminal all together. 

    Sorry if this isn't so clear -- I'm kind of muddled right now!
    I'm using this code based on the "pointellism" tutorial, which writes the image pixels to the screen wonderfully, but I'm wondering how to make the pixels fade away in the same way?  any help would be appreciated.

    1. import fullscreen.*;
    2. import processing.video.*;
    3. FullScreen fs;
    4. PImage erin;
    5. void setup() {
    6.     frameRate(60);
    7.   size(800,800);
    8.   fs = new FullScreen(this);
    9.   fs.enter();
    10.   noCursor();
    11.   erin = loadImage("erin2.jpg");
    12.   background(0);
    13.   smooth();
    14. }
    15. void draw() {
    16.   drawCells();
    17. }
    18. void drawCells() {
    19.   int x = int(random(erin.width));
    20.   int y = int(random(erin.height));
    21.   int loc = x + y*erin.width;
    22.   loadPixels();
    23.   float r = red(erin.pixels[loc]);
    24.   float g = green(erin.pixels[loc]);
    25.   float b = blue(erin.pixels[loc]);
    26.   noStroke();
    27.   fill(r,g,b,100);
    28.   ellipse(x,y,5,5);
    29. }

    I'm controlling 4 DC motors through Processing, using StandardFirmata on the Arduino.
    When I test the motors with a simple sketch in Arduino, they work perfect.  When I try to actuate the motors through Processing, they do nothing.

    - I have checked the syntax of the Arduino library in Processing and I believe I have called the functions correctly. 
    - I have printed a list of serial ports to confirm that I am listening to the correct port.
    - Both StandardFirmata and Processing are set to 9600 baud.
    - If I change the analogWrite() to digitalWrite(pin,HIGH), I am able to turn the motors on.

    Is there something I am missing when calling arduino.analogWrite() in Processing?

    Help, please and thank you!


    1. import processing.serial.*;
      import cc.arduino.*;
      Arduino arduino;

      int motor1 = 3;
      int motor2 = 5;
      int motor3 = 9;
      int motor4 = 10;
      int pulseWidth = 200;

      void setup() {
        size(100,100);
        background(0);
        println(Arduino.list());
        arduino = new Arduino(this, Arduino.list()[0], 9600);
        arduino.pinMode (motor1, Arduino.OUTPUT);
        arduino.pinMode (motor2, Arduino.OUTPUT);
        arduino.pinMode (motor3, Arduino.OUTPUT);
        arduino.pinMode (motor4, Arduino.OUTPUT);
      }

      void draw() {
          arduino.analogWrite(motor1, pulseWidth);
          arduino.analogWrite(motor2, pulseWidth);
          arduino.analogWrite(motor3, pulseWidth);
          arduino.analogWrite(motor4, pulseWidth);
      }
         
       


    you'll recognize this as part of the fire from the 3DFireCube example that comes with Processing.  I'd like to alter this a bit, to either a) give it a "high" state where the fire grows to two-thirds the screen height, or, b) (perhaps more complicated) to somehow create an ellipse of fire where the fire emanates outward from the centre.   I don't understand all areas of this code, so I'm not sure where to make the adjustment to grow the fire in height at X interval.  Can anyone point me in the right direction?


    1. import fullscreen.*;
      import japplemenubar.*;

      /**
       * Fire Cube demo effect
       * by luis2048.
       *
       * A rotating wireframe cube with flames rising up the screen.
       * The fire effect has been used quite often for oldskool demos.
       * First you create a palette of 256 colors ranging from red to
       * yellow (including black). For every frame, calculate each row
       * of pixels based on the two rows below it: The value of each pixel,
       * becomes the sum of the 3 pixels below it (one directly below, one
       * to the left, and one to the right), and one pixel directly two
       * rows below it. Then divide the sum so that the fire dies out as
       * it rises.
       */
       
      // This will contain the pixels used to calculate the fire effect
      int[][] fire;

      // Flame colors
      color[] palette;
      float angle;
      int[] calc1,calc2,calc3,calc4,calc5;
      PGraphics pg;
      FullScreen fs;

      void setup(){
        size(640, 480, P2D);
       
          fs = new FullScreen(this);
          frameRate(24);
          fs.enter();

        // Create buffered image for 3d cube
        pg = createGraphics(width, height, P3D);

        calc1 = new int[width];
        calc3 = new int[width];
        calc4 = new int[width];
        calc2 = new int[height];
        calc5 = new int[height];

        colorMode(HSB);

        fire = new int[width][height];
        palette = new color[255];

        // Generate the palette
        for(int x = 0; x < palette.length; x++) {
          //Hue goes from 0 to 85: red to yellow
          //Saturation is always the maximum: 255
          //Lightness is 0..255 for x=0..128, and 255 for x=128..255
          palette[x] = color(x/3, 255, constrain(x*3, 0, 255));
        }

        // Precalculate which pixel values to add during animation loop
        // this speeds up the effect by 10fps
        for (int x = 0; x < width; x++) {
          calc1[x] = x % width;
          calc3[x] = (x - 1 + width) % width;
          calc4[x] = (x + 1) % width;
        }
       
        for(int y = 0; y < height; y++) {
          calc2[y] = (y + 1) % height;
          calc5[y] = (y + 2) % height;
        }
      }

      void draw() {
        angle = angle + 0.05;

        // Randomize the bottom row of the fire buffer
        for(int x = 0; x < width; x++){
          fire[x][height-1] = int(random(0,190)) ;
        }

        loadPixels();

        int counter = 0;
        // Do the fire calculations for every pixel, from top to bottom
        for (int y = 0; y < height; y++) {
          for(int x = 0; x < width; x++) {
            // Add pixel values around current pixel

            fire[x][y] =
                ((fire[calc3[x]][calc2[y]]
                + fire[calc1[x]][calc2[y]]
                + fire[calc4[x]][calc2[y]]
                + fire[calc1[x]][calc5[y]]) << 5) / 129;

            // Output everything to screen using our palette colors
            pixels[counter] = palette[fire[x][y]];

            // Extract the red value using right shift and bit mask
            // equivalent of red(pg.pixels[x+y*w])
            if ((pg.pixels[counter++] >> 16 & 0xFF) == 128) {
              // Only map 3D cube 'lit' pixels onto fire array needed for next frame
              fire[x][y] = 128;
            }
          }
        }
        updatePixels();
      }
    Hi all,
    I'm having trouble with my code for the lilypad accelerometer (adxl330).  I want to import the real time sensor data from the accelerometer into Processing so that I can "draw" with it.  In my Processing code, do I import the Lilypad sensor data as "arduino.analogRead()" ?  This program compiles fine, but gives me 0s in the serial monitor. 

    1. import cc.arduino.*;
      import processing.serial.*;
      Arduino arduino;

      int sensorPinX = 0;
      int sensorPinY = 1;
      int sensorPinZ = 2; 
      int[] xArray = new int[8];
      int[] yArray = new int[8];
      int[] zArray = new int[8];
      int [] sensorValueX = new int[50];
      int [] sensorValueY = new int[50];
      int [] sensorValueZ = new int[50];

      int BAUDRATE = 9600;
      char DELIM = ',';

      void setup() {
        arduino = new Arduino(this, Arduino.list()[0], 9600);

        int i;
        size(1440, 900);
        noStroke();
        noCursor();
        for (i = 0; i < sensorValueX.length; i++) {
            sensorValueX[i] = 0;
            sensorValueY[i] = 0;
            sensorValueZ[i] = 0;
        }
      }

      void draw() {
        int i;
        int xpos;
        int ypos;
        int zpos;

        background(0);
        noStroke();

        xpos = arduino.analogRead(sensorPinX);
        addEntry(xpos,xArray);
        ypos = arduino.analogRead(sensorPinY);
        addEntry(ypos,xArray);
        zpos = arduino.analogRead(sensorPinZ);
        addEntry(zpos,zArray);

        print(xpos);
        print(" ");
        print(ypos);
        print(" ");
        println(zpos);

        addEntry(getAverage(xArray),sensorValueX); 
        addEntry(getAverage(yArray),sensorValueY);
        addEntry(getAverage(zArray),sensorValueZ);

        //SPHERE
        for (i = 0; i < sensorValueX.length; i++) {
          fill(i*5,i*10,255-i*5); 
          ellipse(width/2 + sensorValueX[i]*1.5, height/1.5 - sensorValueY[i]*1.5, i*2.5, i*2.5);  //x, y, width, height
        }
      }

      int getAverage(int valueArray[]){
        int i;
        int sum = 0;
        int average;
        for (i=0;i<valueArray.length;i++) {
          sum += valueArray[i];
          }
          average = sum/valueArray.length;
          return average;
      }

      void addEntry(int value, int valueArray[]) {
        int i;
        for (i=0;i<valueArray.length-1;i++) {
          valueArray[i]=valueArray[i+1];
          }
        valueArray[valueArray.length-1] = value;
      }



    has anyone done this?  I'd like to look at some recent examples of fire, fireballs, etc. that people have made, but in searching the forum and openprocessing.org I've come up with surprisingly very little.  There are some projects that I am interested in but they were built using a much older version of Processing, and so not all functions seem to work (eg. FireCube 3D).  I'm more interested in newer fire examples, since perhaps some of you have finessed the code for this.

    do let me know. I'd love to see some examples!