Hi! I'm currently doing a project, which I've already asked for some help for, but it seems that another problem has arisen. The project includes the tilt switch which comes with the starter kit. I have to control some type of visuals in Processing with this tilt switch, and have decided on a very simple switch between two different ellipses; a smaller, yellow one and a larger, green one. When I open the Arduino serial monitor, I can clearly see the switch working; turning on and off as I tilt it. However, when I try to see this on/off in Processing, it doesn't seem to be picking it up at all.
Here's my Arduino code (which I borrowed from here: The Terrific Tilt Switch (with Processing) - Make: Basic Arduino Projects - 26 Experiments with Microcontrollers and Electronics (2014)):
// variables for input pin and control LED
int digitalInput = 8;
int LEDpin = 13;
// variable to store the value
int value = 0;
void setup() {
// declaration pin modes
pinMode(digitalInput, INPUT);
pinMode(LEDpin, OUTPUT);
// begin sending over serial port
Serial.begin(9600);
}
void loop() {
// read the value on digital input
value = digitalRead(digitalInput);
// write this value to the control LED pin
digitalWrite(LEDpin, value);
// if value is high then send the letter 'H'; otherwise, send 'L' for low
if (value) Serial.println('H');
else
Serial.println('L');
// wait a bit to not overload the port
delay(250);
}
And here's my Processing code:
import processing.serial.*;
Serial port;
int val;
int padding = 100;
float m;
void setup() {
size(400, 400);
noStroke();
background(200);
port = new Serial(this, "COM3", 9600);
port.bufferUntil('\n');
}
void draw() {
if (port.available()>0) {
val=port.read();
}
if (val==-1) {
ellipse(200, 200, 100, 100);
fill(#FFDE14);
println(port.read());
} else {
ellipse(200, 200, 150, 150);
fill(#10e047);
println(port.read());
}
}
The values I'm getting in Processing only consist of -1, no matter how many times I tilt the switch...