Skip to content

Commit b681054

Browse files
committedMar 11, 2015
More article updates.
1 parent 351b034 commit b681054

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
 

‎DocsGraphics/circuit.idraw

0 Bytes
Binary file not shown.

‎README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ In our next section of code, we have an updateLight method that either sets all
8585

8686
## Step 3: The iOS Software
8787

88-
Since we're a mobile shop, it would seem silly not to write our own custom software to control the project. The only UI we'll need for this is a way to select a Bean, an on/off switch, and a way to specify the color:
88+
Since we're a mobile shop, it would be silly not to write our own custom software to control the project. The only UI we'll need for this is a way to select a Bean, an on/off switch, and a way to specify the color:
8989

9090
![Bean Picker](DocsGraphics/picker.png)![Light Controls](DocsGraphics/light-controls.png)
9191

9292
We'll also include the LightBlue Bean's [iOS/OS X SDK](https://github.com/PunchThrough/Bean-iOS-OSX-SDK), which makes working with the Bean a little easier. Since we are using Bluetooth characteristics to send our data, we could also simply use CoreBluetooth, though including the SDK gives us the flexibility to also take advantage of the Bean's serial connection in the future if we want to.
9393

94+
### The Browser Screen
95+
9496
When the browser for available Beans appears, we use the Bean library to scan for available devices:
9597

9698
- (void)viewDidLoad {
@@ -141,7 +143,24 @@ And when the connection is made, we finally initiate the segue to show the contr
141143
[self performSegueWithIdentifier:@"showBeanSegue" sender:nil];
142144
}
143145

144-
Most of the control panel code just deals with UI. The interesting methods allow us to send an update, with a little bit of data massaging, to the Bean.
146+
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
147+
PTDBean *bean = [self.beanArray objectAtIndex:self.tableView.indexPathForSelectedRow.row];
148+
BeanViewController *beanViewController = [segue destinationViewController];
149+
beanViewController.bean = bean;
150+
}
151+
152+
### The Control Screen
153+
154+
Most of the control panel code just deals with UI. The interesting methods allow us to send an update, with a little bit of data massaging, to the Bean. (ColorSwatchView is simply a UIView. We use the background color to store and display the current color selected.)
155+
156+
157+
- (IBAction)didTapSwitch:(UISwitch*)sender {
158+
[self sendUpdateToBean];
159+
}
160+
161+
- (IBAction)sliderDragCompleted:(UISlider *)sender {
162+
[self sendUpdateToBean];
163+
}
145164

146165
- (void)sendUpdateToBean {
147166
CGFloat red;
@@ -198,6 +217,8 @@ We also read the data from the bean when we display the screen to set the status
198217
self.blueSlider.value = blue;
199218
}
200219

220+
With all this code in place, we can finally send updates to our completed light system!
201221

202222
## Step 4: Profit?
203223

224+
This may not be a practical lighting system for everyone, but for folks with an inclination toward tinkering, it opens up lots of interesting possibilities for customization and improvement. It would be easy to add a variety of animation effects when changing the light's color. One could monitor the Bean's accelerometers so that you can turn the light on and off by thumping the shelf it's mounted under with your fist (I call this ["Fonzie mode"](http://www.dailymotion.com/video/xu7jyb_1st-time-we-see-fonz-hit-the-jukebox-and-stop-and-start-it-upon-command_shortfilms)). The lighting could be automatically adjusted to be more blue in the morning to help you wake up, and more red in the evening so as not to interfere with your sleep, a la [Flux](https://justgetflux.com). And of course one could tie it into various web services to provide quick information on weather, the stock market, etc.

0 commit comments

Comments
 (0)
Please sign in to comment.