I am fairly new to processing and Arduino - I have a coursework deadline for both on Monday (6th January).
I am trying to write a script that uses the mouseX values to turn LEDs on and off. I haven't got any error messages on either of the scripts but currently, nothing happens to the LEDs (they remain off) when I move my mouse. I have tested the circuit with a simpler Arduino code and it is correct so there must be an error in my code!
I would be very grateful for some help. Thanks!
Processing code:
import processing.serial.*;
Serial port;
byte lightsOn;
void setup()
{
size(600,300);
port=new Serial(this,"/dev/cu.usbmodem1411",9600);
}
void draw()
{
background(32,78,95);
rect(300,0,300,300);
noStroke();
fill(185,215,216);
lightsOn=byte(mouseX);
port.write(lightsOn);
println(lightsOn);
}
Arduino code:
#include <Servo.h>
Servo myservo;
int ledpinA=12;
int ledpinB=13;
void setup()
{
Serial.begin(9600);
myservo.attach(ledpinA&&ledpinB);
pinMode(ledpinA,OUTPUT);
pinMode(ledpinB,OUTPUT);
}
void loop()
{
if(0<Serial.available())
{
int data = Serial.read();
if (data>300)
{
digitalWrite(ledpinA, HIGH);
digitalWrite(ledpinB, LOW);
}
else
{
digitalWrite(ledpinB, HIGH);
digitalWrite(ledpinA, LOW);
}
}
}