This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
lab5 [2015/10/25 20:06] dan.tudose |
lab5 [2018/11/09 09:55] (current) dan.tudose |
||
|---|---|---|---|
| Line 17: | Line 17: | ||
| //put your variable definitions here for the data you want to send | //put your variable definitions here for the data you want to send | ||
| //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO | ||
| - | | + | |
| }; | }; | ||
| Line 51: | Line 51: | ||
| blinkLED(); | blinkLED(); | ||
| - | delay(5000); | + | delay(1000); |
| } | } | ||
| Line 59: | Line 59: | ||
| <code C> | <code C> | ||
| - | # | + | # |
| + | |||
| //create object | //create object | ||
| - | ZigduinoTransfer ET; | + | SparrowTransfer ST; |
| + | |||
| struct RECEIVE_DATA_STRUCTURE{ | struct RECEIVE_DATA_STRUCTURE{ | ||
| - | //put your variable definitions here for the data you want to receive | + | //put your variable definitions here for the data you want to send |
| - | //THIS MUST BE EXACTLY THE SAME ON THE OTHER NODE!!! | + | //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO |
| - | | + | |
| - | int pause; | + | |
| }; | }; | ||
| - | |||
| //give a name to the group of data | //give a name to the group of data | ||
| RECEIVE_DATA_STRUCTURE mydata; | RECEIVE_DATA_STRUCTURE mydata; | ||
| + | |||
| + | uint16_t old_index, received_index, | ||
| void setup(){ | void setup(){ | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| - | //start the library, pass in the data details | ||
| - | ET.begin(details(mydata)); | ||
| | | ||
| + | //start the library, pass in the data details | ||
| + | ST.begin(details(mydata)); | ||
| + | |||
| pinMode(11, OUTPUT); | pinMode(11, OUTPUT); | ||
| - | | + | |
| + | |||
| + | } | ||
| + | |||
| + | void blinkLED() | ||
| + | { | ||
| + | digitalWrite(11, | ||
| + | delay(20); | ||
| + | digitalWrite(11, | ||
| } | } | ||
| void loop(){ | void loop(){ | ||
| //check and see if a data packet has come in. | //check and see if a data packet has come in. | ||
| - | if(ET.receiveData()){ | + | if(ST.receiveData() |
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | received_index++; |
| - | delay(mydata.pause * 100); | + | |
| - | | + | if(old_index != 0) |
| - | delay(mydata.pause * 100); | + | lost += mydata.data - old_index |
| - | | + | |
| + | Serial.print("Frame arrived: "); | ||
| + | | ||
| + | | ||
| + | Serial.print(" | ||
| + | | ||
| + | Serial.print(", | ||
| + | Serial.print(lost*100.0/ | ||
| + | | ||
| + | |||
| + | old_index = mydata.data; | ||
| } | } | ||
| - | | + | |
| - | //you should make this delay shorter than your transmit delay or else messages could be lost | + | //optional |
| - | delay(250); | + | |
| } | } | ||
| + | |||
| </ | </ | ||