Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dkrkamesh/ab14ba8c9b75e285de087fe0c8578929 to your computer and use it in GitHub Desktop.
Save dkrkamesh/ab14ba8c9b75e285de087fe0c8578929 to your computer and use it in GitHub Desktop.
// Source Code: Raspberry Pi sending data to the Arduino
const int ledPin = 13;
void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
blink(Serial.read() - '0'); // convert the character '1'-'9' to decimal 1-9
}
delay(500);
}
void blink(int numberOfTimes)
{
for (int i = 0; i < numberOfTimes; i++)
{
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment