JeetRanjan
Published © GPL3+

LengthBlinker

Blink Arduino's LED on pin 13 according to the input provided by you.

BeginnerFull instructions provided733
LengthBlinker

Things used in this project

Story

Read more

Code

LengthBlinker

Arduino
Just upload the code and open Serial Monitor and type anything and send it or press ENTER . The led at pin 13 will blink for the count of input string you have provided.
For example if you enter 'lol' it will blink for 3 times ie equal to the length of the input.
/*
 Name:		lengthBlinker.ino
 Created:	9/28/2017 12:03:23 AM
 Updated: 9/29/2017 01:27:33 AM
 Author:	jeet


 This code will make your arduino's led blink according to the length of input you have provided ..
 Yes this Code is really small and is written just for fun.
 L.....O......L
*/

#define pin 13
// the setup function runs once when you press reset or power the board
void setup() {
	pinMode(13, OUTPUT);
	Serial.begin(250000);
}
int count = 0;
String str;

// the loop function runs over and over again until power down or reset
void loop() {	
	
		str = Serial.readString();  //getting the data from the port
		count = str.length();   
		//finding the length 
		if (count == 0) {
			Serial.println("Please give me some input");

		}
		else
		{
			Serial.println(str);
			//for loop to execute the blinking for count number of times
			for (int i = 0; i < count; i++) 
			{
				digitalWrite(pin, HIGH);
				delay(300);
				digitalWrite(pin, LOW);
				Serial.print("\n blink"); Serial.print(i);
				delay(300);
			}
			delay(500);
			Serial.print("Blinked for ");
			Serial.print(count);
			Serial.print(" Times \n");
			delay(500);
		}
	}

Credits

JeetRanjan

JeetRanjan

2 projects • 0 followers

Comments