Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Many embedded systems are written in C/C++. Since you are building skills in this area, it is important that you are introduced to such an

Many embedded systems are written in C/C++. Since you are building skills in this area, it is important that you are introduced to such an application. We will simulate an Arduino, a simple and popular microcontroller, using this free online editor:

Tinkercad (Links to an external site.)

Our goal is to combine a servo motor, a button, and an LED to create a simple device that could be used for something like an electronic lock!

Setup

  • Create an account and sign in
    • Ignore the option to create a student account. Just create a regular one.
  • Click on circuits in the navigation bar on the left.
  • Click on create new circuit
  • From the drop down box on the right, select Arduino
  • Scroll down and click the Button configuration. Move your cursor to the work area and click again.
  • Click the code button near the top right
    • Observe the code in block format
  • Click the drop down box at the top left of the coding window. Select Blocks + Text. Observe the code, written in C++.
  • The board has several I/O pins for various purposes: Analog input, digitial input / output, analog output via Pulse Width Modulation (PWM), and power supply pins.
    • HIGH represents an output of 5 volts, LOW represents 0 volts
    • setup is called once when the machine boots up
    • loop is called as fast as the processor can call it, depending on how many instructions there are.
      • The core code looks something like this:
        • while(1) { loop() }
  • The Button demo code does the following:
    • Read the state of the button on pin 2
    • If the button is being pressed, light up the LED on pin 13
    • Delay for 10 milliseconds before returning from the loop function
  • If you click Start Simulation you can see the on board LED light up when you click on the button.
  • Read the Arduino Button Tutorial (Links to an external site.)for more information
  • Next, click on the Tinkercad button in the top left corner to go back to the dashboard
  • Create another new circuit
  • This time select Arduino, then servo
  • Read the Arduino Servo Tutorial (Links to an external site.) for more information
    • Note: The servo example uses a loop to sweep angles on the servo. This is not necessary. Regardless of its position, if you call servo_9.write(angle) once, it will move to that angle if it is given enough time. It is not necessary to send the command more than once.
  • Repeat the same process for an LED. This time choose Blink (Links to an external site.) from the Arduino drop down menu.

Instructions

  • Create a project where you combine a button, a servo, and an LED into one Arduino controller
  • Switch your editor to use only C++ text. You may not edit your code using the block editor.
  • Combine the code from each project. Some of the demo code may not be needed.
    • You do not need a loop to move your servo, even though the servo demo has one.
  • If the user has the button pressed down, move the servo to position 180 and turn the LED on.
  • If the button is not being pressed, move the servo to position 0 and turn the LED off.
  • Write a delay at the end of your loop function, something like delay(15), so the simulator does not get overwhelmed.
  • This system could be used for something like an electronic lock.
  • Below is a video showing the end result:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

please dont use chat gpt or other AI 1 6 5 .

Answered: 1 week ago