Hi,
I am a new user of Arduino UNO.
I have run the blinking examples and now I am trying to create programs of my own.
Right now I have created the following sketch:
int val = 0;
int led1 = 2;
int led2 = 8;
int led3 = 12;
int led4 = 13;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
/*
char i = Serial.read();
if (i=='a') {
digitalWrite(led,HIGH);
}
*/
delay(100);
}
void serialEvent() {
while (Serial.available()) {
val = Serial.parseInt();
if(val == 1) {
delay(1000);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
}
else if(val == 0) {
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
}
}
Serial.println("Succesfully received.");
}
Even though the sketch works for led 13, it does not work for the rest of the leds.
I have already checked the connections on the breadboard.
Any ideas what am I missing?
I call the program from Java:
import jssc.SerialPort;
import jssc.SerialPortException;
public class TestCom {
public static void main(String[] args) {
try {
SerialPort com = null;
String arduinoComPortNo = "COM7";
com = new SerialPort(arduinoComPortNo);
com.openPort();
com.setParams(9600,8,1,0);
com.writeString("1");
//com.writeString("0");
com.closePort();
}
catch (SerialPortException ex) {
System.out.println(ex);
}
}
}