/
getDataFromSmartphone.ino
61 lines (49 loc) · 1.55 KB
/
getDataFromSmartphone.ino
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
#include <phyphoxBle.h>
/* In this example we can change the blink interval of our mikrocontroller via phyphox
*/
void receivedData();
long lastTimestamp = 0;
float blinkInterval = 100;
bool led = true;
void setup()
{
Serial.begin(115200);
PhyphoxBLE::start();
PhyphoxBLE::configHandler=&receivedData;
pinMode(LED_BUILTIN, OUTPUT);
//Experiment
PhyphoxBleExperiment getDataFromSmartphone;
getDataFromSmartphone.setTitle("Set Blink Interval");
getDataFromSmartphone.setCategory("Arduino Experiments");
getDataFromSmartphone.setDescription("User can set Blink Interval of Mikrocontroller LED");
//View
PhyphoxBleExperiment::View firstView;
firstView.setLabel("FirstView"); //Create a "view"
//Edit
PhyphoxBleExperiment::Edit Interval;
Interval.setLabel("Interval");
Interval.setUnit("ms");
Interval.setSigned(false);
Interval.setDecimal(false);
Interval.setChannel(1);
firstView.addElement(Interval);
getDataFromSmartphone.addView(firstView); //attach view to experiment
PhyphoxBLE::addExperiment(getDataFromSmartphone); //attach experiment to server
}
void loop()
{
PhyphoxBLE::poll(); //Only required for the Arduino Nano 33 IoT, but it does no harm for other boards.
if(millis()-lastTimestamp>blinkInterval){
lastTimestamp = millis();
led=!led;
digitalWrite(LED_BUILTIN, led);
}
}
void receivedData(){
float receivedInterval;
PhyphoxBLE::read(receivedInterval);
if(receivedInterval>0){
blinkInterval =receivedInterval;
}
Serial.println(blinkInterval);
}