send signal down serial port to arduino
in
Integration and Hardware
•
10 months ago
im trying to send bytes one and zero down the serial port using processing and the arduino recieving the input nd turning a simple led on and off
heres my code for processing:
[code]
import processing.serial.*;
Serial myPort;
void setup()
{
myPort = new Serial(this, Serial.list()[0], 9600);
}
void loop()
{
int i=0;
if(i==0)
{
myPort.write('1');
i = 1;
}
else
{
i = 0;
myPort.write('0');
} // else write zero to port
} // loop method
[/code]
and heres my code for the arduino:
[code]
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);
}
void loop(){
if (Serial.available()>0)
{
delay(1000);
byte input=Serial.read();
if(input == '1')
{
digitalWrite(2, HIGH);
}else{
digitalWrite(2, LOW);
} // else write low
}
}
[/code]
i ran the example led blink program so my connections are good o what can it be? any help? thanks.
1