Skip to content

Commit 020e706

Browse files
committed
Added IntegerEasyTransfer examples
1 parent c5b202e commit 020e706

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <IntegerEasyTransfer.h>
2+
3+
//create object
4+
IntegerEasyTransfer ET;
5+
6+
struct RECEIVE_DATA_STRUCTURE {
7+
//put your variable definitions here for the data you want to receive
8+
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
9+
int16_t blinks;
10+
int16_t pause;
11+
};
12+
13+
//give a name to the group of data
14+
RECEIVE_DATA_STRUCTURE mydata;
15+
16+
void setup() {
17+
Serial.begin(9600);
18+
//start the library, pass in the name of the serial port. Can be Serial,
19+
//Serial1, Serial2, etc.
20+
ET.begin(&Serial);
21+
22+
pinMode(13, OUTPUT);
23+
24+
}
25+
26+
void loop() {
27+
//check and see if a data packet has come in.
28+
if (ET.receiveData()) {
29+
//this is how you access the variables.
30+
//[name of the group].[variable name]
31+
mydata.blinks = ET.readInt();
32+
mydata.pause = ET.readInt();
33+
//since we have data, we will blink it out.
34+
for (int i = mydata.blinks; i > 0; i--) {
35+
digitalWrite(13, HIGH);
36+
delay(mydata.pause * 100);
37+
digitalWrite(13, LOW);
38+
delay(mydata.pause * 100);
39+
}
40+
}
41+
42+
//you should make this delay shorter then your transmit delay or else
43+
//messages could be lost
44+
delay(250);
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <IntegerEasyTransfer.h>
2+
3+
//create object
4+
IntegerEasyTransfer ET;
5+
6+
struct SEND_DATA_STRUCTURE {
7+
//put your variable definitions here for the data you want to send
8+
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
9+
int16_t blinks;
10+
int16_t pause;
11+
};
12+
13+
//give a name to the group of data
14+
SEND_DATA_STRUCTURE mydata;
15+
16+
void setup() {
17+
Serial.begin(9600);
18+
//start the library, pass in the name of the serial port. Can be Serial,
19+
//Serial1, Serial2, etc.
20+
ET.begin(&Serial);
21+
22+
pinMode(13, OUTPUT);
23+
24+
randomSeed(analogRead(0));
25+
26+
}
27+
28+
void loop() {
29+
//this is how you access the variables. [name of the group].[variable name]
30+
mydata.blinks = random(5);
31+
mydata.pause = random(5);
32+
//send the data
33+
ET.writeInt(mydata.blinks);
34+
ET.writeInt(mydata.pause);
35+
ET.sendData();
36+
37+
//Just for fun, we will blink it out too
38+
for (int i = mydata.blinks; i > 0; i--) {
39+
digitalWrite(13, HIGH);
40+
delay(mydata.pause * 100);
41+
digitalWrite(13, LOW);
42+
delay(mydata.pause * 100);
43+
}
44+
45+
delay(5000);
46+
}

0 commit comments

Comments
 (0)