Sending data/numbers from Arduino to Jitter/Max

Hi guys,

I'm having a bit of trouble trying to get my head around this. What I am doing is using a switch with Arduino and counting how many times that the switch has been pressed. The switch is taking the place of a heart rate monitor with a digital output which I will be using later in the project.

What I want to do is send a message to Jitter once the switch has been pressed a certain amount of times to begin playing a movie clip. It will essentially be a 'bang' message in Jitter that I want Arduino to trigger (With a number?) a video to play.

Here is the Arduino Sketch that I am using, it seems to be working fine, it is just getting it to send messages to Jitter that I am having trouble with:

const int buttonPin = 7;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

int val;


int buttonState = 0;        

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);    
  
  Serial.begin(9600);
}

void loop(){
  
  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {    
        
    digitalWrite(ledPin, LOW);
    
    Serial.print("\n Times the button was pressed =  " );                      
    Serial.println(val);      
    
    delay(500);
    
    val++;
    
     }
else {
    
    digitalWrite(ledPin, HIGH);
  }
}

Any help would be appreciated.

You want to count only the switch state changes, don't you. In loop, you want to see if the button is pressed now but wasn't before, right?

As is, the code is incrementing val more often than it should.

How is the switch wired? LOW is pressed?

it seems to be working fine, it is just getting it to send messages to Jitter that I am having trouble with

What kind of trouble? Does Jitter read from the serial port? Does it not like what it is seeing there?

Yes, it is checking to see if the button is pressed now and wasn't before. The switch is LOW when pressed. I am actually using two wires now instead of the switch it was just too stiff and was giving an inaccurate readings.

As for Jitter, to be completely honest I have no clue how to get it to receive messages from Arduino. I'm relatively new to all of this and am under a lot of pressure to get this done asap.

Do you know if there is some extra code that I need to put in to the sketch for this to work? Or do you have any other tips?

Thanks.

if (buttonState == LOW) {

This statement is checking to see if the switch is pressed, with no regard for whether it was pressed last time digitalRead looked.

I know nothing about Jitter. That's why I asked you. You chose to use Jitter, for some presumably good reasons. I presume that one of them was because you knew what it was capable of. I see, now, that that is not the case.

Perhaps someone else can help with that.

I am very familiar with Max/MSP, we did a whole module on it last semester. Jitter patches contain Max objects as well as the Jitter objects. I know very well what Max is capable of, I meant that I was new to the whole serial communication aspect as I have never done it before. I am also familiar with Jitter, I thought myself how to use it as it wasn't covered in the Max/MSP module, but again it is the communication that I am new to.

We also only began working with Arduino at the beginning of February in our Sensor Technology module so I apologize if I came across as ignorant and clueless I was just looking for some help.

No need to apologize for my misunderstanding.

The Arduino is capable of serial communication, using the Serial class. You are currently sending data to the serial port.

I would think that it shouldn't be too difficult to read that data in Jitter. You may need to change how the data is written, to suit Jitter.

Okay cheers thanks a million, I appreciate it.