We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear all
I wonder if anyone can help me here... I am trying to send an integer to Arduino to dim the LED. Below is the rather simple code which works:
When I removed delay(100) from both processing and arduino code, it does not work at all (LED does not dim). when I put delay (50), it works too, but when I put delay(10), it kind of works but the LED is flickering.... I am wondering what is going on here? Has it got anything to do with the speed of loop() and draw()?
thanks Jim
processing:
// import the serial library
import processing.serial.*;
// create a serial port variable
Serial myPort;
void setup(){
size(300,300);
// create an instance of the serial library
myPort = new Serial(this, Serial.list()[4], 9600);
}
void draw(){
//map the mouseX value from (0…width) to (0,255)
float brightness = map(mouseX, 0, width, 0,255);
//convert float to int
int brightness1 = int(brightness);
background(brightness1);//set background colour
myPort.write(brightness1);//write the brightness value to the port
delay(100);
}
Arduino:
int incomingByte = 0;
void setup() {
// initialise serial communication
Serial.begin(9600);
pinMode(9, OUTPUT);
}
void loop() {
//read the data sent from Processing
incomingByte = Serial.read();
analogWrite(9, incomingByte);
delay(100);
}
Answers
}