Skip to content

Commit 85469ad

Browse files
committedMar 3, 2015
Writing RGB value to bean, added bean code to read and respond (on the built-in LED for now).
1 parent a4dcd1b commit 85469ad

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed
 

‎Arduino/rgb_scratch/rgb_scratch.ino

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
rgb_scratch
3+
4+
Checks scratch bank 1. Blinks LED the color of the value passed in.
5+
Byte 0: on/off
6+
Byte 1: Red
7+
Byte 2: Green
8+
Byte 3: Blue
9+
10+
<http://www.punchthrough.com/bean>
11+
12+
*/
13+
14+
15+
void setup()
16+
{
17+
Serial.begin(57600);
18+
}
19+
20+
21+
// the loop routine runs over and over again forever:
22+
void loop()
23+
{
24+
ScratchData thisScratch = Bean.readScratchData(1);
25+
26+
if ( thisScratch.length >= 4 ) {
27+
bool isOn = thisScratch.data[0];
28+
bool r = thisScratch.data[1];
29+
bool g = thisScratch.data[2];
30+
bool b = thisScratch.data[3];
31+
32+
if ( isOn ) {
33+
Bean.setLed(r,g,b);
34+
Bean.sleep(1000);
35+
Bean.setLed(0,0,0);
36+
}
37+
38+
}
39+
40+
Bean.sleep(1000);
41+
}

‎iOSBluetoothLighting/iOSBluetoothLighting.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@
443443
"$(inherited)",
444444
);
445445
INFOPLIST_FILE = iOSBluetoothLightingTests/Info.plist;
446+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
446447
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
447448
PRODUCT_NAME = "$(TARGET_NAME)";
448449
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSBluetoothLighting.app/iOSBluetoothLighting";
@@ -458,6 +459,7 @@
458459
"$(inherited)",
459460
);
460461
INFOPLIST_FILE = iOSBluetoothLightingTests/Info.plist;
462+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
461463
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
462464
PRODUCT_NAME = "$(TARGET_NAME)";
463465
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/iOSBluetoothLighting.app/iOSBluetoothLighting";

‎iOSBluetoothLighting/iOSBluetoothLighting/BeanViewController.m

+22-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ @interface BeanViewController () <PTDBeanDelegate>
1313
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
1414
@property (weak, nonatomic) IBOutlet UILabel *activityLabel;
1515

16+
@property (strong) UIColor *color;
17+
1618
@end
1719

1820
@implementation BeanViewController
@@ -23,6 +25,8 @@ - (void)viewDidLoad {
2325
NSString *activityString = [NSString stringWithFormat:@"Connected to: %@", self.bean.name];
2426
self.activityLabel.text = activityString;
2527
[self.activityIndicator startAnimating];
28+
29+
self.color = [UIColor blueColor];
2630
}
2731

2832
- (void)didReceiveMemoryWarning {
@@ -32,7 +36,24 @@ - (void)didReceiveMemoryWarning {
3236

3337
- (IBAction)didTapSwitch:(UISwitch*)sender {
3438
BOOL switchValue = sender.on;
35-
NSData *payload = [NSData dataWithBytes:&switchValue length:sizeof(BOOL)];
39+
40+
CGFloat red;
41+
CGFloat green;
42+
CGFloat blue;
43+
CGFloat alpha;
44+
[self.color getRed:&red green:&green blue:&blue alpha:&alpha];
45+
46+
Byte redByte = floor( red * 255 );
47+
Byte greenByte = floor( green * 255 );
48+
Byte blueByte = floor( blue * 255 );
49+
50+
Byte dataArray[4];
51+
dataArray[0] = switchValue;
52+
dataArray[1] = redByte;
53+
dataArray[2] = greenByte;
54+
dataArray[3] = blueByte;
55+
56+
NSData *payload = [NSData dataWithBytes:dataArray length:sizeof(dataArray)];
3657
[self.bean setScratchBank:1 data:payload];
3758
}
3859

0 commit comments

Comments
 (0)
Please sign in to comment.