Ok. Processing code is below, as is original pushbutton code for arduino. Am not getting anything in the serial monitor. I am using bytes because the code I had for a push button sends bytes, and this worked perfectly with the processing code so I thought I could just change the if statement? I haven't yet learned about ASCII. Can you explain why I need to use these instead?
Thanks,
Ben.
// import libraries
import processing.serial.*; // serial library
// define objects
Serial port; // define serial object
// variables
int trigger= 0; // has the ultrasonic been triggered?
int frames = 1; // frame counter, so we know when we're at the end
int numOfFrames = 239; // the number of frames in your movie MINUS ONE
int val; // Data received from the serial port
PImage[] theFrames = new PImage[240]; // array for PImages (still images of video)
void setup() {
size( 787 , 576 ); // sub-DV size, smaller is better
frameRate(25); // hopeful!
// load the stills
for(int i=1; i<numOfFrames; i=i+1) {
theFrames[i] = loadImage("Collapse"+ nf((i),3) + ".jpg"); // change the filename of image here
// test that they loaded
if (theFrames[i] != null) {
println("Loaded, " + getTheDate()); // debug
}
else {
println("Error loading the image, " + getTheDate()); // error report
}
}
println(Serial.list()); // prints list of serial ports
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
// UNCOMMENT NEXT TWO LINES
// String portName = Serial.list()[1]; // chose the right one from the list that printed out
// port = new Serial(this, portName, 9600);
}
void draw() {
if (trigger == 1 && frames < numOfFrames) { // if it's triggered
image(theFrames[frames], 0, 0); // draw the frame to the screen
frames++; // increment the frame number
// println("1 debug: frames =" + frames +" trigger =" + trigger ); // debug
}
else if (frames == numOfFrames) { // if we're at the end of the movie
frames = 1; // reset frame counter to first frame
image(theFrames[frames], 0, 0); // draw the frame to the screen
trigger =0; // no longer triggered
// println("2 debug: frames =" + frames +" trigger =" + trigger ); // debug
}
else { // if we're waiting to be triggered
image(theFrames[frames], 0, 0); // draw it
frames = 1; // set frames to 0
// println("3 debug: frames =" + frames +" trigger =" + trigger ); // debug
}
// Triggering code currently set up to respond to key press.
if (keyPressed == true) {
trigger = 1;
// player.play();
}
// // Serial read code. Uncomment this block when you're all connected.
// if ( port.available() > 0) { // If data is available,
// val = port.read(); // read it and store it in val
// }
//
// if (val != 0) { // If the serial value is not 0,
// trigger = 1;
// }
}
String getTheDate() {
int s = second(); // Values from 0 - 59
int m = minute(); // Values from 0 - 59
int h = hour(); // Values from 0 - 23
int d = day(); // Values from 1 - 31
int mon = month(); // Values from 1 - 12
int y = year(); // 2003, 2004, 2005, etc.
return(nf(h, 2) + ":" +nf(m, 2)+":"+ nf(s, 2) + ", " + d +"/"+mon+"/"+y);
}
/*
// Wiring / Arduino Code
// Code for sensing a switch status and writing the value to the serial port.
int switchPin = 4; // Switch connected to pin 4
void setup() {
pinMode(switchPin, INPUT); // Set pin 0 as an input
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (digitalRead(switchPin) == HIGH) { // If switch is ON,
Serial.print(1, BYTE); // send 1 to Processing
} else { // If the switch is not ON,
Serial.print(0, BYTE); // send 0 to Processing
}
delay(100); // Wait 100 milliseconds
}
*/
Moderator edit, on a mission to eliminate italics in software listings. AWOL