Write a sketch in Arduino with two functions; the first function-1 find the value “y” in the equation: ? = ? − 30 . The value “x” is entered by keyboard. The second function-2 test whether the value “y” (calculated with the first function) is a negative number. If it is true, then the function call again function-1 with the value a new value x = x (old value) + 40. Otherwise print the message: “Finished”.
Print all results.
ANS:
int x;
void setup() {
Serial.begin(9600);
delay(2000);
Serial.println("Type value of x ");
}
void loop() {
if(Serial.available()){
x = Serial.read();
}
}
int Function1(int x){
int y;
y = x-30;
Function2(y,x);
}
int Function2(int y,int x){
if (y < 0)
{
x=x+40;
Function1(x);
}
else
{Serial.print("finished");}
}
Screenshot of the code:
Get Answers For Free
Most questions answered within 1 hours.