pinMode(ledPin, OUTPUT); // Set LED pin as an output pin
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
blinks += Serial.read();
Serial.println(blinks);
if (blinks > 0) {
int ledPin = 13;
digitalWrite(ledPin, HIGH); //sets LED on
delay(1000); //waits for a second
digitalWrite(ledPin, LOW); //sets LED off
blinks--;
}
}
You need to tell us more about what the problem is. Does the perl script not get executed? Does it call called, but not behave as expected? Does the Arduino sketch not read any serial data? Does it not blink the LED at all? Does it not blink the correct number of times?
I'm not a perl expert by any stretch of the imagination, but this looks strange:
ser.write(chr(ord(chr(delta))))
delta looks like an integer, since it is the result of subtracting one integer from another. Suppose delta was 3. chr(delta) returns the ascii character that is the 3rd letter in the ascii collating sequence. Then, ord(chr(delta)) converts that letter back to a number (3). Then, chr(ord(chr(delta))) converts it back to a letter. Why?
What happens if delta does not represent a valid letter in the ascii collating sequence?
Some value is read by the Arduino, and assumed to be a number. The LED on pin 13 is turned on, and left on for one second. Then, it is turned off. If blinks is greater than 0, it is almost immediately turned back on again. (The off time is the length of time it takes to toggle a pin to off, to decrement blinks, and to test if blinks is still greater than 0. That's maybe a dozen clock cycles, at 16 million clock cycles per second. I doubt that the human eye can see the off time.)
pinMode(ledPin, OUTPUT); // Set LED pin as an output pin
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
blinks += Serial.read();
Serial.println(blinks);
if (blinks > 0) {
int ledPin = 13;
digitalWrite(ledPin, HIGH); //sets LED on
delay(3000); //waits for 3 seconds
digitalWrite(ledPin, LOW); //sets LED off
blinks--;
}
}