User Tools

Site Tools


lab5

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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
-  uint8_t data;+  uint16_t data;
 }; };
  
Line 51: Line 51:
   blinkLED();   blinkLED();
  
-  delay(5000);+  delay(1000);
 } }
  
Line 59: Line 59:
  
 <code C> <code C>
-#include <ZigduinoTransfer.h> +#include "SparrowTransfer.h" 
 + 
 //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 blinks+  uint16_t data
-  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, lost;
  
 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);
-  +  digitalWrite(11, HIGH);  
 +  
 +
 + 
 +void blinkLED() 
 +
 +  digitalWrite(11, LOW); 
 +  delay(20); 
 +  digitalWrite(11, HIGH);  
 } }
  
 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() == SUCCESS){ 
-    //this is how you access the variables. [name of the group].[variable name] +     
-    //since we have data, we will blink it out.  +    blinkLED(); 
-    for(int i = mydata.blinks; i>0; i--){ +     
-      digitalWrite(11, HIGH); +    received_index++; 
-      delay(mydata.pause * 100); +     
-      digitalWrite(11LOW); +    if(old_index != 0) 
-      delay(mydata.pause * 100); +      lost += mydata.data old_index 1; 
-    }+       
 +    Serial.print("Frame arrived: "); 
 +    Serial.print(mydata.data); 
 +    Serial.print(" "); 
 +    Serial.print("lost: "); 
 +    Serial.print(lost); 
 +    Serial.print(", loss: "); 
 +    Serial.print(lost*100.0/(lost+received_index), 3); 
 +    Serial.println("%"); 
 +       
 +    old_index = mydata.data;
   }   }
-   +  
-  //you should make this delay shorter than your transmit delay or else messages could be lost +  //optional delay, to disable flooding serial interface 
-  delay(250);+  //delay(250);
 } }
 +
 </code> </code>
  
lab5.1445796376.txt.gz · Last modified: 2015/10/25 20:06 by dan.tudose