Вы находитесь на странице: 1из 3

int redLed=9; // Assign redLED to pin 9

int yellowLed=10; // Assign yellowLED to pin 10

int greenLed=11; // Assign greeLED to pin 11

int redOnTime=500; // Declare red pin on time

int redOffTime=500; // Declare red pin off time

int yellowOnTime=500; // Declare yellow pin on time

int yellowOffTime=500; // Declare yellow pin off time

int greenOnTime=500;// Declare green pin on time

int greenOffTime=500; // Declare green pin off time

int numRedBlinks; // Declare the number of times the red LED should blink

int numYellowBlinks; // Declare the number of times the yellow LED should blink

int numGreenBlinks; // Declare the number of times the green LED should blink

String wm1="Welcome to "; // Declare a string varible

String wm2="my thing."; // Declare a string varible

String wm3=wm1+wm2; // Cantonating two string varibles

String redMessage="The red LED is blinking"; // Declare a string varible

String yellowMessage="The yellow LED is blinking"; // Declare a string varible

String greenMessage="The greenMessage is blinking"; // Declare a string varible

void setup() { // put your setup code here, to run once:

Serial.begin(9600); // Turn on the serial port

Serial.println(wm3); // Print the welcome message to the screen

Serial.println(""); // Print a space between lines

pinMode(redLed,OUTPUT); // Tell Arduino that redLedPin is an output pin

pinMode(yellowLed,OUTPUT); // Tell Arduino that yellowLedPin is an output pin

pinMode(greenLed,OUTPUT); // Tell Arduino that greenLedPin is an output pin

void loop() { // put your main code here, to run repeatedly:


Serial.println("How many times do you want the red LED to blink? "); // prompt user for input

while (Serial.available()==0){} // Wait for user input

numRedBlinks=Serial.parseInt(); // Read user input and assign the number to numRedBlinks

Serial.println(""); // Print a blank line

Serial.println("How many times do you want the yellow LED to blink? "); // prompt user for input

while (Serial.available()==0){} // wait for user input

numYellowBlinks=Serial.parseInt(); // Read user input and assign the number to numYellowBlinks

Serial.println(""); // Print a blank line

Serial.println("How many times do you want the green LED to blink? "); // prompt user for input

while (Serial.available()==0){} // wait for user input

numGreenBlinks=Serial.parseInt(); // Read user input and assign the number to numGreenBlinks

Serial.println(""); // Print a blank line

Serial.println(redMessage); // Print the heading "The red LED is blinking"

for (int j=1; j<=numRedBlinks; j=j+1){ // Start of the loop

Serial.print(" This is blink number: "); // Print this sentence

Serial.println(j); // Print the number to the screen (1,2...)

digitalWrite(redLed,HIGH); // Turn red LED on

delay(redOnTime); // Tell Arduino how long to turn it on for

digitalWrite(redLed,LOW); // Turn red LED off

delay(redOffTime); // Tell Arduino how long to turn it off for

Serial.println(""); // Print a blank line

Serial.println(yellowMessage); // Print the heading "The yellow LED is blinking"

for (int j=1; j<=numYellowBlinks; j=j+1){ // Start of the loop

Serial.print(" This is blink number: "); // Print this sentence

Serial.println(j); // Print the number to the screen (1,2...)

digitalWrite(yellowLed,HIGH); // Turn yellow LED on

delay(yellowOnTime); // Tell Arduino how long to turn it on for

digitalWrite(yellowLed,LOW); // Turn red LED off


delay(yellowOffTime); // Tell Arduino how long to turn it off for

Serial.println(""); // Print a blank line

Serial.println(greenMessage); // Print the heading "The green LED is blinking"

for (int j=1; j<=numGreenBlinks; j=j+1){ // Start of the loop

Serial.print(" This is blink number: "); // Print this sentence

Serial.println(j); // Print the number to the screen (1,2...)

digitalWrite(greenLed,HIGH); // Turn green LED on

delay(greenOnTime); // Tell Arduino how long to turn it on for

digitalWrite(greenLed,LOW); // Turn red LED off

delay(greenOffTime); // Tell Arduino how long to turn it off for

Serial.println(""); // Print a blank line

Serial.println(yellowMessage); // Print the heading "The yellow LED is blinking"

for (int j=1; j<=numYellowBlinks; j=j+1){ // Start of the loop

Serial.print(" This is blink number: "); // Print this sentence

Serial.println(j); // Print the number to the screen (1,2...)

digitalWrite(yellowLed,HIGH); // Turn yellow LED on

delay(yellowOnTime); // Tell Arduino how long to turn it on for

digitalWrite(yellowLed,LOW); // Turn red LED off

delay(yellowOffTime); // Tell Arduino how long to turn it off for

Serial.println(""); // Print a blank line

Вам также может понравиться