TolentinoCotesta

Bentel

Nov 9th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const int dataSize = 500;  //Arduino memory is limited (max=1700)
  2.  byte storedData[dataSize];  //Create an array to store the data
  3.  #define ledPin 13           //Onboard LED = digital pin 13
  4.  #define rfReceivePin A0     //RF Receiver data pin = Analog pin 0
  5.  const unsigned int upperThreshold = 100;  //upper threshold value
  6.  const unsigned int lowerThreshold = 80;  //lower threshold value
  7.  int maxSignalLength = 255;   //Set the maximum length of the signal
  8.  int dataCounter = 0;    //Variable to measure the length of the signal
  9.  unsigned long startTime=0;  //Variable to record the start time
  10.  unsigned long attuale=0;  //Variable to record the start time
  11.  unsigned long endTime=0;    //Variable to record the end time
  12.  unsigned long signalDuration=0; //Variable to record signal reading time
  13. int contatore;
  14. int lettura[50];
  15. int letbin[50];
  16. int ver =2;
  17.  
  18.  
  19. void setup() {
  20.   pinMode(ver,OUTPUT);
  21.  contatore=0;
  22.  Serial.begin(9600);
  23.  Serial.println("inizio");
  24.  while(analogRead(rfReceivePin)<1){
  25.       //Wait here until a LOW signal is received
  26.       //startTime=micros();  //Update start time with every cycle.
  27.     //  startTime=(startTime+300);
  28.   }
  29.   startTime=micros();  //Update start time with every cycle.
  30.       startTime=(startTime+2734);
  31. }
  32.  
  33.  
  34. void loop() {
  35.  
  36.  
  37. attuale=micros();
  38.  
  39. if (attuale>=startTime){
  40. contatore=(contatore+1);
  41. digitalWrite(ver, HIGH);
  42. lettura[contatore]=(analogRead(rfReceivePin));
  43. digitalWrite(ver,LOW);
  44.  
  45.  
  46. startTime=(startTime+496);
  47.  
  48. }
  49.  
  50.  
  51. if(contatore==49){
  52.  Serial.println("FINITO");
  53. for (int i=1; i <= 48; i++){
  54.  
  55. if (lettura[i]>= 200){
  56. letbin[i]=1;
  57. Serial.print("1");  
  58. }
  59. //Serial.print(lettura[i]);
  60. //Serial.print(" ");
  61. if (lettura[i]<= 200){
  62. letbin[i]=0;
  63. Serial.print("0");  
  64. }
  65. }
  66.  
  67. //////in Binario
  68. Serial.println(" ");
  69. for (int h=1; h <= 48; h++){
  70. Serial.print(letbin[h]);
  71.  
  72. }
  73.  
  74.  
  75.  
  76. //////////////
  77.  
  78. ////STAMPA CODICE /////////////////////////
  79. Serial.println("");  
  80. int cifra1=((letbin[14]*8)+(letbin[15]*4)+(letbin[16]*2)+(letbin[17]*1));
  81. Serial.print(cifra1,HEX);
  82. Serial.print(" ");  
  83.  
  84. int cifra2=((letbin[18]*8)+(letbin[19]*4)+(letbin[20]*2)+(letbin[21]*1));
  85. Serial.print(cifra2,HEX);
  86. Serial.print(" ");
  87.  
  88. int cifra3=((letbin[23]*8)+(letbin[24]*4)+(letbin[25]*2)+(letbin[26]*1));
  89. Serial.print(cifra3,HEX);
  90. Serial.print(" ");  
  91.  
  92. int cifra4=((letbin[27]*8)+(letbin[28]*4)+(letbin[29]*2)+(letbin[30]*1));
  93. Serial.print(cifra4,HEX);
  94. Serial.print(" ");
  95.  
  96. int cifra5=((letbin[32]*8)+(letbin[33]*4)+(letbin[34]*2)+(letbin[35]*1));
  97. Serial.print(cifra5,HEX);
  98. Serial.print(" ");
  99.  
  100. int cifra6=((letbin[36]*8)+(letbin[37]*4)+(letbin[38]*2)+(letbin[39]*1));
  101. Serial.print(cifra6,HEX);
  102. Serial.print(" ");  
  103.  
  104.  
  105.  
  106. ///////////////////////////////////////////
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113. while(true){}
  114.  
  115. }
  116.  
  117. }
Add Comment
Please, Sign In to add comment