The code below, does exactly as i want in terms of processing the image, and converting it into a stream of values.
however i want it to
1) wait for an initial "ready" command from the ardunio
2) wait for a "ready" command from the arduino in between each and every number transmission.
the arduino is processing the numbers physically, and therefore takes time.
I have used "300" as my ready command because the sketch is dealing in shades between 0 and 255. I figure it it one less thing to worry about if i dont start chucking ascii in there too.
My "commands" can be 300, 301, 302 etc.
I THINK i have narrowed down the lines which need attention to lines 17 and 33. I pressume i need a "serial Event" void in there? but i am dont know what to do with it. All the tutorials i have read and watched (of which there are many) do different things with it, none of which i understand properly. I presume what is required here depends on the context?
Many thanks
Ol
however i want it to
1) wait for an initial "ready" command from the ardunio
2) wait for a "ready" command from the arduino in between each and every number transmission.
the arduino is processing the numbers physically, and therefore takes time.
I have used "300" as my ready command because the sketch is dealing in shades between 0 and 255. I figure it it one less thing to worry about if i dont start chucking ascii in there too.
My "commands" can be 300, 301, 302 etc.
I THINK i have narrowed down the lines which need attention to lines 17 and 33. I pressume i need a "serial Event" void in there? but i am dont know what to do with it. All the tutorials i have read and watched (of which there are many) do different things with it, none of which i understand properly. I presume what is required here depends on the context?
Many thanks
Ol
- import processing.serial.* ;
- Serial myPort;
- int ready = 300; // greyscale is 0-255. decided to use 300+ as commands, to prevent from mixing ascii with numbers.
- PImage img1;
- int cellSize = 10; // size of cells into which the image is split, larger size = less cells
- int squareSize = 300; // size of the working frame
- float greyscale;
- void setup() {
- size(squareSize, squareSize);
- println(Serial.list());
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9600);
- print("Port: ");
- println(myPort);
- myPort.clear();
- myPort.read();
- myPort.bufferUntil(ready); // ********this is SUPPOSED to wait for a "ready" signal from the arduino (sent on button press) It doesn’t, obviosuy
- }
- void draw() {
- background(0);
- img1 = loadImage("grad.jpg"); // image, 300 x 300
- imageMode(CENTER);
- image(img1, (squareSize/2), (squareSize/2)); // draws the image
- for (int y = 0; y < squareSize; y = y + cellSize ) {
- // "carrige return" instruction from processing to the arduino will go in here (probably)
- for (int x = 0; x < squareSize; x = x + cellSize) {
- color c = get(x + cellSize/2, y + cellSize/2);
- float greyscale = brightness(c); // Sets 'greyscale' to 255-0
- println(greyscale); //show the greyscale
- myPort.write(c); // send it to the arduino
- myPort.clear(); // clear the port
- delay (300); // delay for easy reading
- myPort.bufferUntil(ready); // ***** this is SUPPOSED to WAIT until the arduino replies that it is ready.
- }
- }
- }
- void serialEvent (Serial myPort) {
- myPort.read(); // ******* Not really sure what is needed here., or if serial Event is needed at all?
- }