Uh, wrong duplicate thread deleted. Oh well. For the 4th or 5th time, here is my code.
Sketch:
int num_on, num_off, br;
char str[10];
void setup()
{
// pulse the LED to show reset
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(5000);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
Serial.setTimeout (100);
num_on = 100;
num_off = 1000;
}
void loop()
{
// pulse the LED on/off for the specified number of ms
digitalWrite(LED_BUILTIN, HIGH);
delay(num_on);
digitalWrite(LED_BUILTIN, LOW);
delay(num_off);
// check to see if new on/off times have been sent
if (Serial.available()>1) {
br = Serial.readBytes (str,2);
num_on = str[0] * 10;
num_off = str[1] *10;
}
// for debug
Serial.println ("on");
Serial.println (num_on);
Serial.println ("off");
Serial.println (num_off);
Serial.println ("bytes read");
Serial.println (br);
}
Perl:
#!/usr/bin/perl
$f0 = $ARGV[0];
$f1 = $ARGV[1];
open(my $ard, ">","/dev/cu.SLAB_USBtoUART");
printf $ard "%c", $f0;
#close ($ard);
#open(my $ard, ">","/dev/cu.SLAB_USBtoUART");
printf $ard "%c", $f1;
close ($ard);
Works as expected with the two commented-out lines in the middle put back in. But with them commented out, the sketch never succeeds at the Serial.available>1. So 'br' is 0, and num_on and num_off never get updated.