Going Further

There are some obvious improvements that could be made to our application. Right now, there is no indication of what’s going on behind the scenes, which makes debugging difficult. Let’s start to fix that by adding a label to our user interface and hooking this up to the cableConnected and cableDisconnected delegate methods so we know for sure whether the cable is properly connected to our iPad.

Click on the PaduinoViewController.xib interface file to open it in Interface Builder and drag and drop two UILabel elements into the view. Position them at the top of your interface and in the top left corner. Change the text of the first label to be “Cable:” and position the second to the right of that. You can leave the second label with its default text intact, or change it to be something more reasonable for an initial state (like Disconnected). Open up the Assistant Editor and then Ctrl-click and drag from the second label to the associated interface file to create an instance variable and property (see Figure 3-10).

Connecting the UILabel to the interface file

Figure 3-10. Connecting the UILabel to the interface file

Save your changes, then switch to the Standard Editor and return to the PaduinoViewController.m implementation file. Go to the cableConnected and cableDisconnected delegate methods and add the highlighted code:

- (void) cableConnected:(NSString *)protocol {
    [rscMgr setBaud:9600];
    [rscMgr open];
 self.statusLabel.text ...

Get iOS Sensor Apps with Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.