qUESTO è L'ULTIMO TOPIC..PROMETto!!

Allora dopo varie vicessitudini siamo arrivate a voler fare una specie di lampada camaleonte.

una web cam su processing determina i colori >>video(capture)>>colorsorting dopo di che vogliamo con arduino collegare un led RGB che cambia colore a seconda dei colori che rileva la cam..su processing.. -si puo fare? -qualche suggerimento? ho gia istallato le librerie e firmata varie..grazie mille. siamo veramente nelle vostre mani!!!!!! :-/ :'(

se firmata è installato e vi funziona allora è semplicissimo

procuratevi un led RGB

collegatelo ad arduino ai pin 9,10,11

e poi nel codice processing scrivete:

arduino.analogWrite(9,R); arduino.analogWrite(10,G); arduino.analogWrite(11,B);

dove r,g e b sono le variabili che rappresentano l'intensità delle componenti rosso verde e blu del colore

(r, g e b devono avere 0 come valore minimo e 255 come massimo)

m

PS: Potete scrivere quanti topic volete, non esiste nessun limite :)

ma…devo importare le librerie arduino?

import processing.serial.*;

import cc.arduino.*;

arduino.analogWrite(9,R);
arduino.analogWrite(10,G);
arduino.analogWrite(11,B);




/**
 * Color Sorting  
 * by Ben Fry. 
 * 
 * Example that sorts all colors from the incoming video
 * and arranges them into vertical bars.
 */
 
 
import processing.video.*;

Capture video;
boolean cheatScreen;

Tuple[] captureColors;
Tuple[] drawColors;
int[] bright;

// How many pixels to skip in either direction
int increment = 5;


public void setup() {
  size(800, 600, P3D);

  noCursor();
  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 80, 60, 15);
  
  int count = (video.width * video.height) / (increment * increment);
  bright = new int[count];
  captureColors = new Tuple[count];
  drawColors = new Tuple[count];
  for (int i = 0; i < count; i++) {
    captureColors[i] = new Tuple();
    drawColors[i] = new Tuple(0.5, 0.5, 0.5);
  }
}


public void draw() {
  if (video.available()) {
    video.read();
    
    background(0);
    noStroke();

    int index = 0;
    for (int j = 0; j < video.height; j += increment) {
      for (int i = 0; i < video.width; i += increment) {
        int pixelColor = video.pixels[j*video.width + i];

        int r = (pixelColor >> 16) & 0xff;
        int g = (pixelColor >> 8) & 0xff;
        int b = pixelColor & 0xff;

        // Technically would be sqrt of the following, but no need to do
        // sqrt before comparing the elements since we're only ordering
        bright[index] = r*r + g*g + b*b;
        captureColors[index].set(r, g, b);

        index++;
      }
    }
    sort(index, bright, captureColors);

    beginShape(QUAD_STRIP);
    for (int i = 0; i < index; i++) {
      drawColors[i].target(captureColors[i], 0.1);
      drawColors[i].phil();

      float x = map(i, 0, index, 0, width);
      vertex(x, 0);
      vertex(x, height);
    }
    endShape();

    if (cheatScreen) {
      //image(video, 0, height - video.height);
      // Faster method of displaying pixels array on screen
      set(0, height - video.height, video);
    }
  }
}


public void keyPressed() {
  if (key == 'g') {
    saveFrame();
  } else if (key == 'c') {
    cheatScreen = !cheatScreen;
  }
}


// Functions to handle sorting the color data


void sort(int length, int[] a, Tuple[] stuff) {
  sortSub(a, stuff, 0, length - 1);
}


void sortSwap(int[] a, Tuple[] stuff, int i, int j) {
  int T = a[i];
  a[i] = a[j];
  a[j] = T;

  Tuple v = stuff[i];
  stuff[i] = stuff[j];
  stuff[j] = v;
}


void sortSub(int[] a, Tuple[] stuff, int lo0, int hi0) {
  int lo = lo0;
  int hi = hi0;
  int mid;

  if (hi0 > lo0) {
    mid = a[(lo0 + hi0) / 2];

    while (lo <= hi) {
      while ((lo < hi0) && (a[lo] < mid)) {
        ++lo;
      }
      while ((hi > lo0) && (a[hi] > mid)) {
        --hi;
      }
      if (lo <= hi) {
        sortSwap(a, stuff, lo, hi);
        ++lo;
        --hi;
      }
    }

    if (lo0 < hi)
      sortSub(a, stuff, lo0, hi);

    if (lo < hi0)
      sortSub(a, stuff, lo, hi0);
  }
}

questo è ciò che ho scritto suprocessing ,importando le seriali etc…ma non funge :(((

grazie cmq ;D

Eseguite le seguenti operazioni: 1. imparate tutto il possibile su "Firmata" dal playground 2. installate firmata seguendo gli esempi contenuti e fatelo funzionare 3. integrate le 3 righe che vi ho mandato dentro al codice cercando di ragionare dove potrebbero andare bene...

piazzare a caso nel codice non serve a nulla...

PS: ma dove studiate?

m

ISIA ROMA

cmq io il firmata l'ho istallato dal v2 faccio firmata_standard e mi questo errore..

hardware\libraries\Firmata/Firmata.h:61: error: typedef 'callbackFunction' is initialized (use __typeof__ instead)


hardware\libraries\Firmata/Firmata.h:61: error: 'byte' was not declared in this scope


hardware\libraries\Firmata/Firmata.h:61: error: expected primary-expression before 'int'


hardware\libraries\Firmata/Firmata.h:64: error: typedef 'sysexCallbackFunction' is initialized (use __typeof__ instead)


hardware\libraries\Firmata/Firmata.h:64: error: 'byte' was not declared in this scope


hardware\libraries\Firmata/Firmata.h:64: error: 'byte' was not declared in this scope


hardware\libraries\Firmata/Firmata.h:64: error: 'byte' was not declared in this scope


hardware\libraries\Firmata/Firmata.h:64: error: 'argv' was not declared in this scope


hardware\libraries\Firmata/Firmata.h:81: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:81: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:86: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:87: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:88: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:90: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:91: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:91: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:91: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:95: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:95: error: 'callbackFunction' has not been declared


hardware\libraries\Firmata/Firmata.h:96: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:97: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:98: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:98: error: 'sysexCallbackFunction' has not been declared


hardware\libraries\Firmata/Firmata.h:98: error: 'void FirmataClass::attach(int, int)' cannot be overloaded


hardware\libraries\Firmata/Firmata.h:95: error: with 'void FirmataClass::attach(int, int)'


hardware\libraries\Firmata/Firmata.h:99: error: 'byte' has not been declared


hardware\libraries\Firmata/Firmata.h:104: error: 'byte' does not name a type


hardware\libraries\Firmata/Firmata.h:105: error: ISO C++ forbids declaration of 'byte' with no type


hardware\libraries\Firmata/Firmata.h:105: error: expected ';' before '*' token


hardware\libraries\Firmata/Firmata.h:107: error: 'byte' does not name a type


hardware\libraries\Firmata/Firmata.h:108: error: 'byte' does not name a type


hardware\libraries\Firmata/Firmata.h:109: error: 'byte' does not name a type


hardware\libraries\Firmata/Firmata.h:110: error: 'byte' does not name a type


hardware\libraries\Firmata/Firmata.h:112: error: 'boolean' does not name a type


hardware\libraries\Firmata/Firmata.h:115: error: 'callbackFunction' does not name a type


hardware\libraries\Firmata/Firmata.h:116: error: 'callbackFunction' does not name a type


hardware\libraries\Firmata/Firmata.h:117: error: 'callbackFunction' does not name a type


hardware\libraries\Firmata/Firmata.h:118: error: 'callbackFunction' does not name a type


hardware\libraries\Firmata/Firmata.h:119: error: 'callbackFunction' does not name a type


hardware\libraries\Firmata/Firmata.h:122: error: 'sysexCallbackFunction' does not name a type


 In function 'void setup()':

ma poi cmq devo importare la libreria di arduino su proccessing nel codice.

" import cc.arduino.*;"

grazie...se abbiamo altri prob..chiedo.

che versione di arduino?

12!!

ah

provate con l'11... il 12 è stato rilasciato senza essere testato a fondo

ora riprovo con l'11....credo che ti chiederò altre cose,grazie grazie mille,abbiamo l'esame martedi prossimo...quindi stiamo parecchio in crisi. ;)

festaaaa..il firmata finalmente non mi da errore...e sembra cosi che arduino e processing siano di nuovo amici:D adesso comnciamo a programmare anzi riprogrammare il ColorSorting e farlo diventare una lampada camaleonte :D a domani...grassie ;)

Allora eccoci qua…
ti ringrazio ancora per l’attenzione che ci dai…
adesso abbiamo modificato il codice cosi…

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;
int R = 9;
int G = 10;
int B = 11;




/**
 * Color Sorting  
 * by Ben Fry. 
 * 
 * Example that sorts all colors from the incoming video
 * and arranges them into vertical bars.
 */
 
 
import processing.video.*;

Capture video;
boolean cheatScreen;

Tuple[] captureColors;
Tuple[] drawColors;
int[] bright;

// How many pixels to skip in either direction
int increment = 10;


public void setup() {
  size(800, 600, P3D);
  {
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[1]); // v2
  //arduino = new Arduino(this, Arduino.list()[0], 57600); // v1

}

  noCursor();
  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 80, 60, 15);
  
  int count = (video.width * video.height) / (increment * increment);
  bright = new int[count];
  captureColors = new Tuple[count];
  drawColors = new Tuple[count];
  for (int i = 0; i < count; i++) {
    captureColors[i] = new Tuple();
    drawColors[i] = new Tuple(0.5, 0.5, 0.5);
  }
}


public void draw() {
  if (video.available()) {
    video.read();
    
    background(0);
    noStroke();
    
    arduino.analogWrite(9,R);
    arduino.analogWrite(10,G);
    arduino.analogWrite(11,B);


    int index = 0;
    for (int j = 0; j < video.height; j += increment) {
      for (int i = 0; i < video.width; i += increment) {
        int pixelColor = video.pixels[j*video.width + i];

        int R = (pixelColor >> 16) & 0xff;
        int G = (pixelColor >> 8) & 0xff;
        int B = pixelColor & 0xff;

        // Technically would be sqrt of the following, but no need to do
        // sqrt before comparing the elements since we're only ordering
        bright[index] = R*R + G*G + B*B;
        captureColors[index].set(R, G, B);

        index++;
      }
    }
    sort(index, bright, captureColors);

    beginShape(QUAD_STRIP);
    for (int i = 0; i < index; i++) {
      drawColors[i].target(captureColors[i], 0.1);
      drawColors[i].phil();

      float x = map(i, 0, index, 0, width);
      vertex(x, 0);
      vertex(x, height);
    }
    endShape();

    if (cheatScreen) {
      //image(video, 0, height - video.height);
      // Faster method of displaying pixels array on screen
      set(0, height - video.height, video);
    }
  }
}


public void keyPressed() {
  if (key == 'g') {
    saveFrame();
  } else if (key == 'c') {
    cheatScreen = !cheatScreen;
  }
}


// Functions to handle sorting the color data


void sort(int length, int[] a, Tuple[] stuff) {
  sortSub(a, stuff, 0, length - 1);
}


void sortSwap(int[] a, Tuple[] stuff, int i, int j) {
  int T = a[i];
  a[i] = a[j];
  a[j] = T;

  Tuple v = stuff[i];
  stuff[i] = stuff[j];
  stuff[j] = v;
}


void sortSub(int[] a, Tuple[] stuff, int lo0, int hi0) {
  int lo = lo0;
  int hi = hi0;
  int mid;

  if (hi0 > lo0) {
    mid = a[(lo0 + hi0) / 2];

    while (lo <= hi) {
      while ((lo < hi0) && (a[lo] < mid)) {
        ++lo;
      }
      while ((hi > lo0) && (a[hi] > mid)) {
        --hi;
      }
      if (lo <= hi) {
        sortSwap(a, stuff, lo, hi);
        ++lo;
        --hi;
      }
    }

    if (lo0 < hi)
      sortSub(a, stuff, lo0, hi);

    if (lo < hi0)
      sortSub(a, stuff, lo, hi0);
  }
}

e quando lo faccio partire il programma funziona , i led in corrispondenzadei colori che vede non si accendono…
e mi da questo errore

NullpointerException




Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7

:-?

Siamo arrivate ad un punto questo:

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;
int R=9;
int G=10;
int B=11;






/**
 * Color Sorting  
 * by Ben Fry. 
 * 
 * Example that sorts all colors from the incoming video
 * and arranges them into vertical bars.
 */
 
 
import processing.video.*;

Capture video;
boolean cheatScreen;

Tuple[] captureColors;
Tuple[] drawColors;
int[] bright;

// How many pixels to skip in either direction
int increment = 5;


public void setup() {
  
  size(800, 600, P3D);
  {
  //println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[1]); // v2
  //arduino = new Arduino(this, Arduino.list()[0], 57600); // v1

}

noCursor();
  // Uses the default video input, see the reference if this causes an error
  video = new Capture(this, 80, 60, 15);
  
  int count = (video.width * video.height) / (increment * increment);
  bright = new int[count];
  captureColors = new Tuple[count];
   drawColors = new Tuple[count];
  for (int i = 0; i < count; i++) {
    captureColors[i] = new Tuple();
    drawColors[i] = new Tuple(0.5, 0.5, 0.5);
  }
}


public void draw() {
  if (video.available()) {
    video.read();
    
    background(0);
    noStroke();
    
    

    int index = 0;
    for (int j = 0; j < video.height; j += increment) {
      for (int i = 0; i < video.width; i += increment) {
        int pixelColor = video.pixels[j*video.width + i];

        int R = (pixelColor >> 16) & 0xff;
        int G = (pixelColor >> 8) & 0xff;
        int B = pixelColor & 0xff;
        
        // Technically would be sqrt of the following, but no need to do
        // sqrt before comparing the elements since we're only ordering
        bright[index] = R*R + G*G + B*B;
        captureColors[index].set(R, G, B);
        

    
        index++;
        arduino.analogWrite(9,R);
    arduino.analogWrite(10,G);
    arduino.analogWrite(11,B);
  
    
 }
 
    }
    sort(index, bright, captureColors);

    beginShape(QUAD_STRIP);
    for (int i = 0; i < index; i++) {
      drawColors[i].target(captureColors[i], 0.1);
      drawColors[i].phil();

      float x = map(i, 0, index, 0, width);
      vertex(x, 0);
      vertex(x, height);
    }
    endShape();

    if (cheatScreen) {
      //image(video, 0, height - video.height);
      // Faster method of displaying pixels array on screen
      set(0, height - video.height, video);
    }
  }
    
}


public void keyPressed() {
  if (key == 'g') {
    saveFrame();
  } else if (key == 'c') {
    cheatScreen = !cheatScreen;
  }
  
}


// Functions to handle sorting the color data


void sort(int length, int[] a, Tuple[] stuff) {
  sortSub(a, stuff, 0, length - 1);
}


void sortSwap(int[] a, Tuple[] stuff, int i, int j) {
  int T = a[i];
  a[i] = a[j];
  a[j] = T;

  Tuple v = stuff[i];
  stuff[i] = stuff[j];
  stuff[j] = v;
}


void sortSub(int[] a, Tuple[] stuff, int lo0, int hi0) {
  int lo = lo0;
  int hi = hi0;
  int mid;

  if (hi0 > lo0) {
    mid = a[(lo0 + hi0) / 2];

    while (lo <= hi) {
      while ((lo < hi0) && (a[lo] < mid)) {
        ++lo;
      }
      while ((hi > lo0) && (a[hi] > mid)) {
        --hi;
      }
      if (lo <= hi) {
        sortSwap(a, stuff, lo, hi);
        ++lo;
        --hi;
      }
    }

    if (lo0 < hi)
      sortSub(a, stuff, lo0, hi);

    if (lo < hi0)
      sortSub(a, stuff, lo, hi0);
  }
}

PS:insieme al programma c’è uno sketch denominato Tuple.

// Simple vector class that holds an x,y,z position.

class Tuple {
  float x, y, z;

  public Tuple() { }

  public Tuple(float x, float y, float z) {
    set(x, y, z);
  }

  public void set(float x, float y, float z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }
  
  public void target(Tuple another, float amount) {
    float amount1 = 1.0 - amount;
    x = x*amount1 + another.x*amount;
    y = y*amount1 + another.y*amount;
    z = z*amount1 + another.z*amount;
  }
  
  public void phil() {
    fill(x, y, z);
  }
}

dove i tre colori dei led si accendono tutti e modulando l’intesità della luce e basta, e non cambiano però tonalità ,fanno una specie di sfarfallio,ed il programma sullo schermo è molto rallentato e scuro.
mmm…in parole povere dobbiamo rendere più netti i colori.
aiutooo :’( :-/ :slight_smile: