-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRfduinoSensor.ino
More file actions
91 lines (72 loc) · 3.08 KB
/
Copy pathRfduinoSensor.ino
File metadata and controls
91 lines (72 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
This RFduino sketch demonstrates a full bi-directional Bluetooth Low
Energy 4 connection between an iPhone application and an RFduino.
This sketch works with the rfduinoLedButton iPhone application.
The button on the iPhone can be used to turn the green led on or off.
The button state of button 1 is transmitted to the iPhone and shown in
the application.
*/
/*
Copyright (c) 2014 OpenSourceRF.com. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <RFduinoBLE.h>
// pin 3 on the RGB shield is the red led
// (can be turned on/off from the iPhone app)
int led = 3;
int aPin = 1; // select the input pin for the potentiometer
void setup() {
// led turned on/off from the iPhone app
pinMode(led, OUTPUT);
// button press will be shown on the iPhone app)
pinMode(button, INPUT);
// this is the data we want to appear in the advertisement
// (if the deviceName and advertisementData are too long to fix into the 31 byte
// ble advertisement packet, then the advertisementData is truncated first down to
// a single byte, then it will truncate the deviceName)
RFduinoBLE.advertisementData = "ledbtn";
RFduinoBLE.deviceName = "DadsArm";
//This variable allows you to set the BLE transmit power in dBm. You can select any value between -20 to +4 dBm
//in 4dBm increments. (ex. -20, -16, -12, -8, -4, 0, +4)
RFduinoBLE.txPowerLevel = -20; //Sets the transmit power to max +4dBm
// start the BLE stack
RFduinoBLE.begin();
}
void loop() {
int a = analogRead(aPin);
String aString = String(a);
char sArray[aString.length() + 1];
aString.toCharArray(sArray,aString.length());
RFduinoBLE.send(sArray,aString.length()-1);
delay(100);
}
void RFduinoBLE_onDisconnect()
{
// don't leave the led on if they disconnect
digitalWrite(led, LOW);
}
void RFduinoBLE_onReceive(char *data, int len)
{
// if the first byte is 0x01 / on / true
if (data[0])
digitalWrite(led, HIGH);
else
digitalWrite(led, LOW);
}