Question

In: Computer Science

hot use blutooth on your app stimulation to connect to a device. xcode swift. please inclide...

hot use blutooth on your app stimulation to connect to a device. xcode swift. please inclide a code if possible.

Solutions

Expert Solution

Download the Xcode starter project. The starter project includes the view controller and base Core Bluetooth implementation to save you time. You’ll add more code to interface with the BLE Shield later on in the tutorial.

Next, download and install the Arduino IDE from the Arduino Download page; it’s available for Windows, Mac OS X and Linux platforms. You’ll use the Arduino IDE to write and compile the code for the Arduino. Ensure you grab the latest release version, not the beta or nightly builds.

The Basic Design of your App

Your finished project will consist of an iOS app that will send messages via Bluetooth to the BLE Shield module. The module will then send the message to the Arduino board to tell the servo which position it should rotate to.

Here’s an example use-case of your project:

  1. The user of the iOS app moves the slider to the middle position.
  2. The app sends the number 90, which represents 90 degrees in this case, to the BLE Shield module using the active Bluetooth connection.
  3. The BLE Shield transfers the number 90 to the Arduino board.
  4. The Arduino board rotates the servo to the 90 degree position.

To begin, you’ll work with the Arduino IDE and program the board logic.

Programming the Arduino

Start the Arduino IDE; you’ll see the editor appear with a blank document, or “sketch”, as shown below:

Before doing anything else, click File\Save in the top menu and save the current file to a convenient location as Arduino_Servo_Controller. This creates a folder in your save location that contains a file with a .ino file extension.

Before you start writing code, you’ll need to set up the IDE to communicate with the Arduino Uno board.

Select Tools\Board\Arduino Uno to let the IDE know what kind of board you’ll be dealing with. Next, connect the Uno to your computer with the USB cable as shown below:

Once that’s done, select Tools\Serial Port\… and select the USB port the Arduino is connected to. Generally it’s similar to /dev/tty.usbserial… or /dev/tty.usbmodem….

At this point the Arduino IDE is ready for programming.

Add the code below to your project using the Arduino IDE:

// Arduino Bluetooth LE Servo Controlled by iOS
 
void setup() // Called only once per startup
{ 
} 
 
void loop() // Continuous loop
{
}

Illuminating an LED

The main objective of your Arduino program in this project is to receive the one-byte messages coming from the BLE Shield and use the contents of the message to set the servo’s position. But before you get too involved into the servo code, it would be nice to test your current connections.

Replace the code in your project with the following:

// Arduino Bluetooth LE Servo Controlled by iOS

int LED = 13;     // Most Arduino boards have an onboard LED on pin 13

void setup()  // Called only once per startup
{ 
  pinMode(LED, OUTPUT);     // Set pin as an output
  digitalWrite(LED, HIGH);  // Turn on LED (ie set to HIGH voltage)
} 

void loop() // Continuous loop
{
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
  digitalWrite(LED, HIGH);
}

Since most Arduino boards have an onboard LED on pin 13, you can use the illumination of the LED as confirmation that your Arduino program is executing properly. You set the LED variable to 13 to refer to that pin.

In setup(), you set the initial state of the board. pinMode(LED, OUTPUT) sets pin 13 as a digital output, which means that the voltage on this pin can be set to HIGH (+5v) or LOW (0v). digitalWrite() sets the pin’s voltage; in the code above you’ve set it to HIGH to illuminate the LED.

After setup() has finished, loop() will run continuously. delay() will wait a certain number of milliseconds which you’ll use to get the LED to blink. After a 500ms delay, you turn the LED off by writing the value LOW; after another delay, you turn the LED back on.

Click the Verify button again to compile the program and check for any syntax errors. If your program compiles without issue, you’ll see Done Compiling in the status bar of the Arduino IDE. If not, read the status bar message for an indication of where you’ve messed up, fix the error and click the Verify button to make sure you’ve squashed the bug for good.

Now it’s time to program the code to the Arduino board and test the LED.

Make sure your Arduino is connected to your computer with the USB cable then click the Upload button (the one with the right arrow icon) to program the Arduino board. Once the upload process has finished, the Done uploading message should appear in the status bar .

Check your Arduino board, and you should see the LED start to blink.

Hope this helps you. Please give an upvote. Thank you.


Related Solutions

I need swift programming code and instruction of app Named Shortest path. Please explain at the...
I need swift programming code and instruction of app Named Shortest path. Please explain at the end of the code how to run the app on Xcode. Thanks
Upload the 3D brain app onto your mobile device or visit the 3D brain app website...
Upload the 3D brain app onto your mobile device or visit the 3D brain app website below. Using your textbook and the app, please identify two structures in the brain. Name the structures, describe where they are located, and describe their functions. Based on case studies described in the app, discuss what is known about damage to these areas. In addition, discuss any new potential treatments for disorders associated with damage to these structures. You may also use outside links...
Please use C++ for Mac (XCode) In this program, a user can search for a name...
Please use C++ for Mac (XCode) In this program, a user can search for a name within a list of names. Here are the steps the program will implement: 1. Reads the names from the file names.txt into a vector that stores strings. 2. Sorts the names in alphabetical order using selection sort. 3. The program then prompts the user to enter a name. 4. The program then uses binary search to see if the name is in the list....
Stimulation (Please read the simulation before answering the questions . Please do not scan your answer,...
Stimulation (Please read the simulation before answering the questions . Please do not scan your answer, type please) Hey Ben. You’re getting an admission in the next 15 minutes coming from the outpatient clinic. BEN: Okay, what can you tell me about this client? JAN: Well, Susan Choi is 33 years old. (PATIENT) She’s been followed for depression over the past six months and is being admitted for acute mania. She is on administrative leave from her employment as a...
Please describe your favorite food in terms of the sense receptors which are stimulated, stimulation of...
Please describe your favorite food in terms of the sense receptors which are stimulated, stimulation of nerve fibers, impulse transmission to the CNS, sensations (memories and experiences), and perception for the sense of smell, taste, sight, and hearing.
1. Types of groups and teams (Connect, Perform) Use your knowledge of groups and teams to...
1. Types of groups and teams (Connect, Perform) Use your knowledge of groups and teams to answer the following questions. Please select the answer that best completes the sentence. In business organizations, most employees work in --------------- . For each example presented in the following table, identify the concept being illustrated. Example Problem-solving Team Virtual Team Cross-functional Team Self-directed Team Once the housekeeping unit of a small hotel was organized into this type of team, the employees took responsibility for...
use android studio or MIT inventor Create a Presidents Quiz App for your project with the...
use android studio or MIT inventor Create a Presidents Quiz App for your project with the following requirements: You must have images Buttons Label Conditional Statement Homepage with instructions Sound (music, buzzer, etc.) - Ensure you are using the correct layout: Gravity(Android Studio), Horizontal or Vertical Arrangement (MIT). - 40POINTS Points System (indicating how many answers they got wrong/correct). 20POINT 1-2 questions per President (45+ questions)
1. Choose a diagrammatic device such as IS-LM and demonstrate your use of it to show...
1. Choose a diagrammatic device such as IS-LM and demonstrate your use of it to show policy effects.
Please use minitab The air flow through a value on an automotive air pollution control device...
Please use minitab The air flow through a value on an automotive air pollution control device is believed to be controlled by three discrete factors; Arm Length, Spring Load, and Bobbin Depth. Use the data given below to determine if any of the factors have a statistically significant impact on average air flow. Arm Length Spring Load Bobbin Depth Air Flow 0.595 100 1.095 0.6 0.605 70 1.095 0.28 0.605 100 1.105 0.72 0.595 70 1.095 0.46 0.595 70 1.095...
3. Managing international operations (Connect/Perform) Use your knowledge of overseas management to complete the following sentences....
3. Managing international operations (Connect/Perform) Use your knowledge of overseas management to complete the following sentences. You are an HR manager for P & G, an established company that has been doing business around the world for many years. P & G is looking for new managers for some of their overseas operations. You would be most likely to try to find _________________ if you wanted to reassure political officials that your employees would abide by the cultural standards of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT