I am having a strange problem and banging my head into the wall.
I have some code on arduino (a Mega) that works fine but when I transfer that code to processing/Firmata using the arduino library it doesn't seem to work. I just want to push a button and have things happen on the computer.
So with the arduino code I have:
if (digitalRead(53)==HIGH) {
Serial.println("53!");
digitalWrite(13, HIGH);
delay(50);
}
And with processing I have:
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup() {
size(470, 280);
arduino = new Arduino(this, Arduino.list()[1], 57600);
arduino.pinMode(53, Arduino.INPUT);
}
void draw() {
background(0);
fill(255);
if (arduino.digitalRead(53) == Arduino.HIGH) {
ellipse(280, 280, 280, 280);
}
}
But yet I cannot get that ellipse to draw. Oddly, if I change the HIGH to a LOW in the code and run the program, the ellipse is there. So it seems to notice the button maybe....there must be some small thing I'm missing here! I tried changing the caps on Arduino and arduino but that didn't work, I have simplified the code so it's exactly the same as the Arduino code! When I run the arduino library test programs in Processing everything works fine so I know I have everything hooked up correctly....
What am I doing wrong???
**edit: the OUTPUT test program works in the arduino library for processing but the INPUT program does not. Does the library not work with an arduino Mega?
I have been looking around for code in processing that would demonstrate different cell behaviors like protein transporting, DNA repair, cell death, etc....I think for a lot of these things there are formulas/equations...so I think it could be animated in a language like Processing. I actually don't know much about it...I'm just a visual artist looking for some inspiration and knowledge.
Has anyone done this? I feel like somewhere there must be a web page of bio grad students who have all this...if no one has done this does anyone know much about biology and they could point me to a page with some formulas that would be not too difficult to transfer into Processing to animate?
Hi,
I'm trying to use the get() method to tell me colors...so I can make a button map behind an image.
When I click on a red color I made in photoshop with the rgb of (255,0,0)...get() will return all sorts of different numbers. Same with (0,255,0) etc. It isn't consistent. It is giving me for (255,0,0): -260350, -64256, -196352, -131072, etc. Why is this? Why doesn't it return the same color value every time?
I am using code like this:::
void mousePressed(){
color c = myImage.get(mouseX,mouseY);
println(c); //(to test out);
if (colors[3] == c){ ///////////the colors[3] in the array would be a number i get back from get() like -256 or -196352..
snip[3].trigger(); play a sound /////////////I tried making in an RGB value but that didn't work...
}
I have a .jpg of a piano. When the mouse goes over the different keys I want to make different tones. The keys are all at angles and the same color so there's no easy way to pick them out. So, like in HTML how you can create image maps, how would you go about this in processing? Do I just make an array of the location of all the pixels in each key? I was doing println(mouseY*width+mouseX); and just going over the keys and writing down the coords. I stopped because it seems like there's got to be an easier way to do this...I couldn't find any info in the forums because I think I lack the exact vocabulary to find what I want.
Hopefully I'm making myself clear, though :-)
Thanks!
Is it possible to have a GSCapture object and a OpenCV object in the same program? I have two separate programs, one that tracks a face with OpenCV and one that tracks a color with GSCapture but when I merge them together I get errors all over the place...as I slowly combine them the first error I get is when I add video = new GSCapture(this, width, height, 30);.....i get NullPointerException at image( opencv.image(), 0, 0 );
is there any way around this or is it because I'm using two different libraries to access my webcam?
I wrote a simple little program that tracks a face using OpenCV and puts a mask image over the face. Basically it's the same as an OpenCV tutorial I just use PImage to put an image over the face instead of rect(); like in the library example.
However, in my program, oddly enough, the .png image that I use fades away after about 20 seconds. Anyone know what's going on here? Here is the code and thanks so much for any help!
Hello,
I'm trying to make a color recognition program where when a color, say, red, that the camera picks up is in a certain area of the screen, a unique sound will play in each divided area. I can get it to work fine but, of course, the sound keeps playing when the color is in that area. I've been messing around with the logic of this, trying to get the sound to play only once, but something is just off and the program is behaving strangely. I will copy the part of the code that isn't working right. How do I get it to just play this sound once when entering the each section or "chamber??" I know I've seen tutorials that deal with a similar problem but I just can't find them. Any help is much appreciated!! :
//faulty logic to get the yellow circle to play a unique note once during entry in to each chamber. myswitch is //a boolean variable defined before setup as just"boolean myswitch;"
if ((colorX < one)&&(colorX>0)) { if (myswitch) { println("FIRST CHAMBER"); snip[1].trigger(); delay(dl); myswitch=false; } }
else if ((colorX > one)&&(colorX<two)) { if (myswitch) { println("SECOND CHAMBER"); snip[2].trigger(); delay(dl); myswitch=false; } }
else if ((colorX>two)&&(colorX<three)) { if (myswitch) { println("THIRD CHAMBER"); snip[3].trigger(); delay(dl); myswitch=false; } }
else if ((colorX>three)&&(colorX<width)) { if (myswitch) { println("FOURTH CHAMBER"); snip[4].trigger(); delay(dl); myswitch=false; }
Hello,
I'm writing a program that tracks a color on a blue screen and depending on which part of the screen the color is on, it plays a little tone (i.e. - person with red dot on leg moves around and some sounds play while a little yellow dot moves along a blue screen)
The program is constantly crashing and won't run for very long. I get # A fatal error has been detected by the Java Runtime Ennironment: EXCEPTION_ACCESS_VIOLATION (0x0000005 at pc=0x7c342eee, pid = 4680, tid=3988 etc etc etc etc...
Thanks so much for any help!
here is the code:
/** * Color Tracking code mostly by: Justin Brooks based on original code: Brightness Tracking by Golan Levin. * * Tracks the pixel closest in color to specified color and makes a sound depending in which quadrant the color is in...sound stuff by me. */
import codeanticode.gsvideo.*; import ddf.minim.*; Minim minim; AudioSample[] snip = new AudioSample[15]; GSCapture video; int dl = 300;
void setup() { size(320, 240); // Change size to 320 x 240 if too slow at 640 x 480 // Uses the default video input, see the reference if this causes an error video = new GSCapture(this, width, height, 30); //noStroke(); smooth(); minim = new Minim(this); for (int i = 1; i < snip.length; i++) { snip[i] = minim.loadSample("samp" + i + ".wav"); } }
void draw() { background(0,0,255); stroke(0); float two = width*.5; float one = width*.25; float three = width*.75; line(one, 0, one ,height); line(two, 0, two, height); line(three, 0, three, height);
if (video.available()) { video.read();
//image(video, 0, 0, width, height); // Draw the webcam video onto the screen int colorX = 0; // X-coordinate of the closest in color video pixel int colorY = 0; // Y-coordinate of the closest in color video pixel float closestColor = 10000; //we set this to be abritrarily large, once program runs, the first pixel it scans will be set to this value // Search for the closest in color pixel: For each row of pixels in the video image and // for each pixel in the yth row, compute each pixel's index in the video video.loadPixels(); int index = 0; for (int y = 0; y < video.height; y++) { for (int x = 0; x < video.width; x++) { // Get the color stored in the pixel color pixelValue = video.pixels[index]; // Determine the color of the pixel float colorProximityBox = abs(red(pixelValue)-255)+abs(green(pixelValue)-0)+abs(blue(pixelValue)-0);
// If that value is closer in color value than any previous, then store the // color proximity of that pixel, as well as its (x,y) location if (colorProximityBox < closestColor) { closestColor = colorProximityBox; closestColor=closestColor-5; //was 10 ...thoguht behind this is that it once it "locks" on to an object of color, it wont let go unless something a good bit better (closer in color) comes along colorY = y; colorX = x; } index++; } } // Draw a large, yellow circle at the brightest pixel fill(255, 204, 0, 128); noStroke(); ellipse(colorX, colorY, 30, 30); if (colorX < one) { println("FIRST CHAMBER"); snip[3].trigger(); delay(dl); }
if ((colorX > one)&&(colorX<two)) { println("SECOND CHAMBER"); snip[4].trigger(); delay(dl); }
if ((colorX>two)&&(colorX<three)) { println("THIRD CHAMBER"); snip[10].trigger(); delay(dl); }
if (colorX>three) { println("FOURTH CHAMBER"); snip[6].trigger(); delay(dl); }
I am trying to learn to use the tweet stream library. Is that library going to not work soon because of what's said in
this post?
Anyway, below is a very, very simple program where a random dot is placed on the screen every time a certain word is tweeted. If the word being searched is just "the" or "a" I get a lot of dots being drawn. However, if I use something like a trending topic (i.e- #ismilewhen or ismilewhen or bb11 (big brother11)) or anything like that, I get maybe 3-5 dots in the course of a few minutes whereas on search.twitter.com I see that these words are being tweeted 100s of times a minute. Is it in my programming or is it the library?
Also, could I just use the java twitter4j library? How would I place that in my Processing library folder? I put it in there and imported all the libraries, trying to run
this sketch on my PC but it didn't work.
So here is the little program. Thanks so much for any help!!!!
import com.twitter.processing.*;
String tweetText = ""; String search = "the"; int counter;
void setup() { size(800,800); background(0); TweetStream s = new TweetStream(this, "stream.twitter.com", 80, "1/statuses/sample.json", "THISISMYUSERNAME", "THISISMYPASSWORD"); //// what does that 80 mean? s.go(); ///////what does this s.go(); mean? }
void draw() { int index = tweetText.indexOf(search); if (index >= 0) { ellipse(random(800), random(800), 20, 20); }
I am having trouble exporting sketches with PImage in them. When I export normal sketches it works fine but with images, either as URLs or as .jpgs in the sketch folder i just get a little 100px white box. If I open the stand alone .jar file the sketch works that way.
Any ideas what I'm doing wrong? I just want to publish some little sketches online.
I want to make a program that makes an array of every pixel from an image and then randomizes the array and reprints out the pixels. So for example you could make an abstract image from a normal .jpg....or even maybe rearrange and sort the pixels by color....go from there and do a bunch of stuff.
I'm trying to figure out exactly what the built in pixels[] array does. It says that the values of the array are of the color datatype. If i do something like println(myimage.pixels[400]); (just picking the 400th pixel at random here) I get a number that doesn't make sense to me like -9544132. If I try to assign a color variable to that pixel it doesn't work, i.e. color c = myimage.pixels[400]; Using the get(); function it works fine capturing a color. I know I'm way off base here...so what is that weird number? What can I do to get started writing this little program? I'm pretty sure I need to use the pixels[]; array...I just don't fully understand it.
I'm trying to write a simple little program that interacts with an Arduino. Basically you step on 3 different Force Sensitive Resistors. Each FSR is assigned to a different picture on the computer monitor that Processing gives you. When I write this program with simple key presses (i.e - press the key '1', it gives you this picture, press the key '2', that picture) it works no problem.
However, when I have it communicate with the Arduino I can only get the last picture in my if statements to load but the print() statements all work and give me the value of the FSR.
import processing.serial.*;
PImage[] imgs = new PImage[4]; int FSR1; int FSR2; int FSR3;
Serial myPort;
void setup() {
size (1200,1000); String[] mypicnames = {"dancing_mam1.png","dancing_mam2.png","dancing_mam3.png","dancing_mam4.png"}; for (int i = 0; i < mypicnames.length; i++) { imgs[i] = loadImage(mypicnames[i]); }
myPort = new Serial(this, Serial.list()[1], 9600); myPort.bufferUntil('\n'); }
void draw() {
if (FSR1 > 1) { background(255); image(imgs[0], 400, 100); ///here the image does not load print(FSR1); ///but here it prints out this value print(","); }
if (FSR2 > 1) { background(255); image(imgs[1], 400,100); //here the image does not load print(FSR2); //but it prints out this value print(","); }
if (FSR3 >1) { background(255); image(imgs[2], 400,100); //here the image DOES load AND the value prints out print(FSR3); //if I comment out this code, than the second if statement works. print(","); } else { background(255); //this code works no problem image(imgs[3], 400, 100); }
}
void serialEvent(Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) { inString = trim(inString);