Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////////////////////
- - Arduino UNO code: blinking LEDS with Serial monitor user input
- /////////////////////////////////////////////////////////////////////////////////////
- int greenLED=9; // Green led on pin 9
- int yellowLED=10; // Yellow led on pin 10
- int greenOnTime=25; // Amount of time that the green led is on
- int greenOffTime=100; // Amount of time that the green led is off
- int yellowOnTime=100; // Amount of time that the yellow led is on
- int yellowOffTime=100; // Amount of time that the yellow led is off
- int greenBlinks=10; // Amount of blinks for the green led
- int yellowBlinks=10; // Amount of blinks for the yellow led
- int randomReboot; // Simulate a fake reboot, just for the fun
- String greenMessage="The green LED is blinking!"; // String that will be printed if green led starts blinking
- String yellowMessage="The yellow LED is blinking!"; // String that will be printed if yellow led starts blinking
- void setup() {
- pinMode(greenLED,OUTPUT); // Declare green pin function, it needs to blink, so its an output
- pinMode(yellowLED,OUTPUT); // Declare yellow pin function, it needs to blink, so its an output
- Serial.begin(9600); // Opens a connection trough the USB cable
- Serial.println("Made by Justin Manig"); // Welcome message
- Serial.println("Feel free to edit"); // Welcome message
- Serial.println(" "); // Welcome message
- }
- void loop() {
- Serial.println("How many times needs the green LED to blink?"); // Ask user for input green led
- while(Serial.available() == 0){}; // Wait untill user sends data
- greenBlinks=Serial.parseInt(); // If user sends data, parse the data to the greenBlinks int
- Serial.println("And how long must the green led stay on?");
- while(Serial.available() == 0){};
- greenOnTime=Serial.parseInt();
- Serial.println("How many times needs the yellow LED to blink?"); // Ask user for input yellow led
- while(Serial.available() == 0){}; // Wait until user sends data
- yellowBlinks=Serial.parseInt(); // If user sends data, parse the data to the yellowBlinks int
- Serial.println("And how long must the yellow led stay on?");
- while(Serial.available() == 0){}
- yellowOnTime=Serial.parseInt();
- Serial.println(greenMessage); // Show the string for the green led
- for(int j=1; j<greenBlinks; j++) // Loop trough this code until max blinks is reached
- {
- Serial.print("|"); // Print this text to the screen when green led blinks
- digitalWrite(greenLED,HIGH); // Let the green led blink
- delay(greenOnTime); // Time untill green led turns off
- digitalWrite(greenLED,LOW); // put the green led off
- delay(greenOffTime); // Time untill green or yellow led turns on
- }
- Serial.println(" "); // If it's time to start with the yellow led, print a blank line
- Serial.println(yellowMessage); // Show the string for the yellow led
- for(int j=1; j<yellowBlinks; j++) // Loop trough this code until max blinks is reached
- {
- Serial.print("|"); // Print this text to the screen when yellow led blinks
- digitalWrite(yellowLED,HIGH); // Let the yellow led blink
- delay(yellowOnTime); // Time untill yellow led turns off
- digitalWrite(yellowLED,LOW); // put the yellow led off
- delay(yellowOffTime); // Time untill yellow led turns on or rebooting simulation starts
- }
- Serial.println(" "); // Print a new line when starting rebooting simulation
- for(int j=10; j<100; j=j+10) // Simulate percentage, 10 to 100
- {
- randomReboot=random(10,500); // Random delay int to look more natural
- Serial.print("Rebooting... "); // Print this text when simulating reboot
- Serial.print(j); // Print percentage when simulating reboot
- Serial.println("%"); // Print percentage char when simulating reboot
- digitalWrite(greenLED,HIGH); // Turn the green led on
- digitalWrite(yellowLED,HIGH); // Turn the yellow led on
- delay(randomReboot); // When green and yellow leds are on, delay it with a random delay
- digitalWrite(greenLED,LOW); // Turn green led off
- digitalWrite(yellowLED,LOW); // Turn yellow led off
- delay(randomReboot); // hen green and yellow leds are off, delay it with a random delay
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement