Does anyone have the information about keyboard input such as entering a value in the serial monitor to delay the blink rate of an led? thanks
This code blinks an LED at a rate proportional to a received digit that can be typed into the serial monitor (enter a value between 0 and 9)
const int ledPin = 13; // pin the LED is connected to
int blinkRate; // blink rate stored in this variable
void setup()
{
Serial.begin(9600); // Initialize serial port to send and receive at 9600 baud
pinMode(ledPin, OUTPUT); // set this pin as output
}
void loop()
{
if ( Serial.available()) // Check to see if at least one character is available
{
char ch = Serial.read();
if(ch >= '0' && ch <= '9') // is this an ascii digit between 0 and 9?
{
blinkRate = (ch - '0'); // ASCII value converted to numeric value
blinkRate = blinkRate * 100; // actual blinkrate is 100 mS times received digit
}
}
blink();
}
// blink the LED at with the on and off times determined by blinkRate
void blink()
{
digitalWrite(ledPin,HIGH);
delay(blinkRate); // delay depends on blinkrate value
digitalWrite(ledPin,LOW);
delay(blinkRate);
}