Computer Science Make a C++ programming ARDUINO UNO where the 1 Ultrasonic Sensor is the input and 1 servo motor(180 degree) is output. // Do no use delay function.(Only if it involved interupt function.) // Only use millis function or Interupt Function. // At a certain distance, the servo motor will spin 0 to 90 degree(Make it stop there for 3 seconds) then back to 0 degree. // At a certain distance, the servo motor will spin 0 to 135 degree (Make it stop there for 3 seconds) to 0 degree. // Make sure it is multipurpose. // U may modify the code here. // #include Servo srv; int servo_angle =0; #define maxdistance 15 unsigned long startTime_servo=0; unsigned long interval_servo =20; int time1=1; void setup() { Serial.begin(9600); pinMode(6, OUTPUT); pinMode(5, INPUT); pinMode(2, OUTPUT); pinMode(3, OUTPUT); srv.attach(7); } void loop() { unsigned currentTime= millis(); digitalWrite(6, LOW); digitalWrite(6, HIGH); int d=pulseIn(5,HIGH); d=d/29/2; digitalWrite(13, HIGH); Serial.println(d); Serial.println(time1);    srv.write(0);     if(d<=10 && d>1)     {           servo1();     }     else if(d<=maxdistance && d>=10)     {           servo2();     } } void servo1() {     digitalWrite(3, HIGH);     digitalWrite(2, LOW);     delay(1000);     srv.write(135);     delay(2500);     srv.write(0);     digitalWrite(3, LOW);     digitalWrite(2, HIGH);     digitalWrite(4, LOW);     delay(3000);    } void servo2() {     delay(5000);     digitalWrite(3, HIGH);     digitalWrite(2, LOW);     delay(1000);     srv.write(135);     delay(2500);     srv.write(0);     digitalWrite(3, LOW);     digitalWrite(2, HIGH);     digitalWrite(4, LOW);     delay(3000);

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
 

Computer Science

Make a C++ programming ARDUINO UNO where the 1 Ultrasonic Sensor is the input and 1 servo motor(180 degree) is output.
//
Do no use delay function.(Only if it involved interupt function.)
//
Only use millis function or Interupt Function.
//
At a certain distance, the servo motor will spin 0 to 90 degree(Make it stop there for 3 seconds) then back to 0 degree.
//
At a certain distance, the servo motor will spin 0 to 135 degree (Make it stop there for 3 seconds) to 0 degree.
//
Make sure it is multipurpose.
//
U may modify the code here.
//
#include<Servo.h>
Servo srv;
int servo_angle =0;
#define maxdistance 15
unsigned long startTime_servo=0;
unsigned long interval_servo =20;
int time1=1;
void setup()
{
Serial.begin(9600);
pinMode(6, OUTPUT);
pinMode(5, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
srv.attach(7);
}

void loop()
{
unsigned currentTime= millis();
digitalWrite(6, LOW);
digitalWrite(6, HIGH);
int d=pulseIn(5,HIGH);
d=d/29/2;
digitalWrite(13, HIGH);
Serial.println(d);
Serial.println(time1);
   srv.write(0);
    if(d<=10 && d>1)
    {
          servo1();
    }
    else if(d<=maxdistance && d>=10)
    {

          servo2();
    }

}
void servo1()
{
    digitalWrite(3, HIGH);
    digitalWrite(2, LOW);
    delay(1000);
    srv.write(135);
    delay(2500);
    srv.write(0);
    digitalWrite(3, LOW);
    digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(3000);   
}

void servo2()
{
    delay(5000);
    digitalWrite(3, HIGH);
    digitalWrite(2, LOW);
    delay(1000);
    srv.write(135);
    delay(2500);
    srv.write(0);
    digitalWrite(3, LOW);
    digitalWrite(2, HIGH);
    digitalWrite(4, LOW);
    delay(3000);
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY