Created
May 7, 2018 20:02
-
-
Save truckershitch/6f8692c322ee7f28868450d4e1efe50a to your computer and use it in GitHub Desktop.
Arduino Heartbeat File Monitor - blinks a binary code in response to blink_media_activity.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Heartbeat File Meter | |
* by truckershitch | |
* | |
* Added blink limit to prevent runaway blinking on boot | |
* Cleaned up loop and variables | |
* 11/22/17 | |
* | |
* based on | |
* Numerical Echo | |
* by Martijn | |
* 22 Nov 2008 | |
* Listen to serial input coming from the computer. If the input is not 0, | |
* pulse that number of heartbeats. | |
*/ | |
const int blinkOn = 250; // timeframe that the LED is switched ON | |
const int ASC_ZERO = 48; // ASCII for 0 (zero) | |
void blink_led(int value) { | |
int count = value - ASC_ZERO; // number of beats | |
if (count <= 15) { // validate input | |
for (int i = 1; i <= count; i++) { | |
digitalWrite(LED_BUILTIN, HIGH); // LED on | |
delay(blinkOn); | |
digitalWrite(LED_BUILTIN, LOW); // LED off | |
delay(blinkOn); | |
} | |
digitalWrite(LED_BUILTIN, LOW); // LED off | |
delay(4 * blinkOn); // LED off - pausing here | |
} | |
} | |
void setup() { | |
Serial.begin(19200); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
if (Serial.available()) { | |
int input = Serial.read(); // listen for input | |
if (input > ASC_ZERO) { | |
blink_led(input); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment