Loading...
Logo
Processing Forum

Force sensor

in Integration and Hardware  •  1 years ago  
Hello everyone, 

Im having some coding/syntax problems

im trying to use a force sensor to activate a video during a loop in processing, 
i have uploaded standard firmata onto my arduino and incorporated the arduinoinput code into my working code. (at the moment im using a spacebar keystroke to activate the second movie)

i have what i feel should be working but i seem to be getting syntax errors were i didn't have them before. can anyone please help?

Copy code
  1. /**
  2.  * Loop. 
  3.  * 
  4.  */

  5. import processing.video.*;
  6. import processing.serial.*;
  7. import cc.arduino.*;
  8. Arduino arduino;

  9. Movie myMovie, your movie;

  10. void setup() {
  11.   size(960, 540, P2D);
  12.   background(0);
  13.   arduino = new Arduino(this, Arduino.list()[0], 57600);
  14.     for (int i = 0; i <= 13; i++)
  15.     arduino.pinMode(i, Arduino.INPUT);
  16.     
  17.   // Load and play the video in a loop
  18.   myMovie = new Movie(this, "Movie1.mov");
  19.   myMovie.loop();

  20. }

  21. void movieEvent(Movie myMovie) {
  22.   myMovie.read();
  23. }
  24. void keyTyped(){

  25.     for (int i = 0; i <= 13; i++) {
  26.     if (arduino.digitalRead(i) == Arduino.HIGH)
  27.      yourMovie = new Movie(this, "Movie2.mov");
  28.     else myMovie.loop();
  29.  { 
  30.  yourMovie = new Movie(this, "Movie2.mov");

  31. }
  32. }
  33. void draw

  34.   image(myMovie, 0, 0, width/1, height/1);
  35.   image(yourMovie, 0, 0, width/1, height/1);
  36. }

Replies(3)

Re: Force sensor

1 years ago
Indeed, this part is full of errors:
Copy code
  1. void keyTyped(){

  2.     for (int i = 0; i <= 13; i++) {
  3.     if (arduino.digitalRead(i) == Arduino.HIGH)
  4.      yourMovie = new Movie(this, "Movie2.mov");
  5.     else myMovie.loop();
  6.  { <- Why an opening brace here?
  7.  yourMovie = new Movie(this, "Movie2.mov");

  8. } <- This closes the extra opening brace, not the for loop
  9. } <- Thus this closes the for loop, not the keyTyped function
  10. void draw <- No opening brace here?

  11.   image(myMovie, 0, 0, width/1, height/1);
  12.   image(yourMovie, 0, 0, width/1, height/1);
  13. }
Trick: use Ctrl+T to reformat your code, some errors become clearer.
Although it might fail in case of errors...

Re: Force sensor

1 years ago
Ok so i made the changes that you said with the braces but im still getting errors. it says unexpected token about the void draw at the bottom

Re: Force sensor

1 years ago
Aw, too bad...

Ah, um, I forgot to mention that it should be void draw(), not void draw.