It's the code in the Arduino Due side, the PC side Processing code will be in next post.
int led = 13;
int incomingByte = 0;
void setup() {
pinMode(led, OUTPUT);
//Setup Serial Port with baud rate of 9600
Serial.begin(9600);
Serial.println("Press H to turn LED ON");
Serial.println("Press L to turn LED OFF");
}
void loop() {
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
if(incomingByte == 'H'){
digitalWrite(led, HIGH);
Serial.println("LED ON");
}else if(incomingByte == 'L'){
digitalWrite(led, LOW);
Serial.println("LED OFF");
}else{
Serial.println("invalid!");
}
}
}
Hey!
ReplyDeleteThanks for sharing, I'm currently working through the same tutorial.
I was just wondering if you knew why the code had to use H or L? I'v searched everywhere and can't find a reason.
Cheers
Just assign a key to control the LED, such that you can type a character in PC side using Serial Monitor of Arduino Software. You can assign any character you want.
Delete