0% found this document useful (0 votes)
6 views

Assignment #10 - Solutions

Uploaded by

yukizyx230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment #10 - Solutions

Uploaded by

yukizyx230
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1

void setup(){
Serial.begin (9600);
}

void loop(){
Serial.println ("Enter your name:");

while (Serial.available () == 0){


}
String yourName = Serial.readString();

Serial.print ("Hello ");


Serial.println (yourName);

delay (500);
}

Q2
void setup(){
Serial.begin (9600);
}

void loop(){
Serial.println ("Enter a number:");

while (Serial.available() == 0){


}
double yourNum = Serial. parseFloat();

double powFour = pow (yourNum, 4);

Serial.print ("Your number to the power of 4 is: ");


Serial.println (powFour,3);

delay (500);
}
Q3
const int LED1 = 4;
const int LED2 = 12;

void setup(){
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}

void loop(){

unsigned long start = millis();

digitalWrite(LED1, HIGH); while loop - 计时3s


int state = 1;

while ((millis() - start) <= 3000){


digitalWrite(LED2, state);
delay (100);
state = !state;
}

digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
delay (2000);

You might also like