Change number of pixels in images using resize() function
Display the digital version of the output array using draw()
Use arrays to cycle through the pixels in an image and modify them
Send RGB values in array to Arduino
Testing:
Different modes of serial sending
Different methods of reading in feed
Arduino
Tasks:
Read in RGB values
Send RGB values to LEDs
Testing:
FastLED library
NeoPixel library
Current Serial Processing
PROCESS: Send the RGB values in three arrays — one for each value. Iterate through these arrays in Arduino and convert all three into one RGB color for each LED in the array. Then display those values.
Processing:
import processing.video.*;import processing.serial.*; Capture cam;Serial myPort;void setup() { size(490, 490); //490,490 // w, h // 400, 500 println((Object[])Serial.list()); String portName = Serial.list()[0]; myPort = new Serial(this, portName, 9600); String[] cameras = Capture.list(); if (cameras.length == 0) { println("There are no cameras available for capture."); exit(); } else { println("Available cameras:"); for (int i = 0; i < cameras.length; i++) { println(i); println(cameras[i]); } } cam = new Capture(this, cameras[0]); cam.start();} void captureEvent(Capture cam) { cam.read();} void draw() { loadPixels(); cam.loadPixels(); String gSend = ""; String rSend = ""; String bSend = ""; for (int x = 0; x < cam.width; x+=92) { //cam.width 640 for (int y = 0; y < cam.height; y+=69) { //cam.height 480 int loc = x + y * cam.width; float r = red(cam.pixels[loc]); float g = green(cam.pixels[loc]); float b = blue(cam.pixels[loc]); r = constrain(r, 0, 255); g = constrain(g, 0, 255); b = constrain(b, 0, 255); //print(str(int(red)) + " "); if (gSend == "" || rSend == "" || bSend == "") { gSend = "G" + str(int(g)); rSend = "R" + str(int(r)); bSend = "B" + str(int(b)); } else { gSend = gSend + "," + str(int(g)); rSend = rSend + "," + str(int(r)); bSend = bSend + "," + str(int(b)); } //problems might be: the video is live so the next pixel it gets can be from the new frame/image } }//end of nested for-loop myPort.write(gSend); delay(1500);//1500 println("g Sent"); myPort.write(rSend); delay(1500); println("r Sent"); myPort.write(bSend); println("b Sent"); delay(1500);}//end of method
Arduino:
#include <Adafruit_NeoPixel.h>#define PIN 5#define NUMPIXELS 49 //the size of our prototype arrayAdafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);int g[NUMPIXELS];int r[NUMPIXELS];int b[NUMPIXELS];int counter = 0;String valG = "";String valR = "";String valB = "";String val = ""; void setup() { pixels.begin(); pixels.show(); Serial.begin(9600);} void loop() { while (valG == "" || valR == "" || valB == "") { pixels.setPixelColor(25, pixels.Color(0, 0, 0)); pixels.show(); if (Serial.available()) { val = Serial.readString(); if (val.charAt(0) == 'G') { valG = val.substring(1); pixels.setPixelColor(0, pixels.Color(100, 0, 0)); pixels.show(); } if (val.charAt(0) == 'R') { valR = val.substring(1); pixels.setPixelColor(1, pixels.Color(0, 100, 0)); pixels.show(); } if (val.charAt(0) == 'B') { valB = val.substring(1); pixels.setPixelColor(2, pixels.Color(0, 0, 100)); pixels.show(); } } pixels.setPixelColor(25, pixels.Color(0, 50, 100)); pixels.show(); } for (int k = 0; k < NUMPIXELS; k++) { g[k] = valG.substring(0, valG.indexOf(',')).toInt(); //sets each value in the array as the corresponding value in the string --> atoi makes the string into an int valG = valG.substring(valG.indexOf(',') + 1); r[k] = valR.substring(0, valR.indexOf(',')).toInt(); //sets each value in the array as the corresponding value in the string --> atoi makes the string into an int valR = valR.substring(valR.indexOf(',') + 1); b[k] = valB.substring(0, valB.indexOf(',')).toInt(); //sets each value in the array as the corresponding value in the string --> atoi makes the string into an int valB = valB.substring(valB.indexOf(',') + 1); }// find a way to see what is being print out here ^ for (int i = 0; i < NUMPIXELS; i++) { pixels.setPixelColor(i, pixels.Color(g[i], r[i], b[i])); pixels.show(); } valG = ""; valR = ""; valB = ""; // delay(200);}
Preliminary Serial Processing
Tests whether RGB values can be sent, received, and displayed in our Processing-Arduino system.