Go Down

Topic: Hall effect sensor (Arduino to processing) (Read 554 times) previous topic - next topic

kfeigeles

Hi

I am new to Arduino.

I am working on a project using hall effect sensors to trigger a processing sketch. I am having trouble figuring out the correct syntax for void draw(). I am able to get a processing sketch to show up but when I run the code but I am not able to get each hall sensor to trigger its own sketch.

I have posted the code below.

Thank you in advance for helping me.

import processing.serial.*;
import cc.arduino.*;
int sensorPin = 2;
int sensorPin2 = 3;
int sensorPin3 = 4;
int sensorPin4 = 5;
int sensorPin5 = 6;
int sensorPin6 = 7;
int sensorPin7 = 8;
int sensorPin8 = 9;
int sensorPin9 = 10;
int sensorPin10 = 11;

//boolean digitalRead;

PImage WSP;
PImage APT;
PImage BET;
PImage CHANGE;
PImage DIRT;
PImage HOME;
PImage ST;
PImage SAD;
PImage TNS;
PImage SEX;

//call arduino
Arduino arduino;
Serial myPort;
int val;

void setup(){
  fullScreen();
  //myPort = new Serial(this, "/dev/cu.usbmodem1421", 9600);
  arduino = new Arduino(this,Arduino.list()[3], 57600);
  arduino.pinMode(sensorPin, Arduino.OUTPUT);
  arduino.pinMode(sensorPin2, Arduino.OUTPUT);
  arduino.pinMode(sensorPin3, Arduino.OUTPUT);
  arduino.pinMode(sensorPin4, Arduino.OUTPUT);
  arduino.pinMode(sensorPin5, Arduino.OUTPUT);
  arduino.pinMode(sensorPin6, Arduino.OUTPUT);
  arduino.pinMode(sensorPin7, Arduino.OUTPUT);
  arduino.pinMode(sensorPin8, Arduino.OUTPUT);
  arduino.pinMode(sensorPin9, Arduino.OUTPUT);
  arduino.pinMode(sensorPin10, Arduino.OUTPUT);
 
  //images:
  WSP = loadImage("WSP.jpg");
  APT = loadImage("APT.jpg");
  BET = loadImage("BET.jpg");
  CHANGE = loadImage("CHANGE.jpg");
  DIRT = loadImage("DIRT.jpg");
  HOME = loadImage("HOME.jpg");
  ST = loadImage("ST.jpg");
  SAD = loadImage("SAD.jpg");
  TNS = loadImage("TNS.jpg");
  SEX = loadImage("SEX.jpg");
}

void draw(){
  if(arduino.digitalRead(sensorPin10) == Arduino.HIGH){
  }else{
    image(WSP, width/2-320, height/2-180, 760, 500);
  }
  if(arduino.digitalRead(sensorPin2) == Arduino.HIGH){
  }else{
    image(APT, width/2-320, height/2-180, 760, 500);
  }
}

PaulS

Quote
but when I run the code but I am not able to get each hall sensor to trigger its own sketch.
In the same way that the Arduino can only run ONE sketch at a time, Processing can only run ONE sketch at a time. So, you're screwed from the get-go.

Triggering different behavior in the same sketch is a completely different story and IS possible.

Once you've displayed an image, you never erase it, so your Processing sketch makes no sense.
The art of getting good answers lies in asking good questions.

Go Up