Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int dataSize = 500; //Arduino memory is limited (max=1700)
- byte storedData[dataSize]; //Create an array to store the data
- #define ledPin 13 //Onboard LED = digital pin 13
- #define rfReceivePin A0 //RF Receiver data pin = Analog pin 0
- const unsigned int upperThreshold = 100; //upper threshold value
- const unsigned int lowerThreshold = 80; //lower threshold value
- int maxSignalLength = 255; //Set the maximum length of the signal
- int dataCounter = 0; //Variable to measure the length of the signal
- unsigned long startTime=0; //Variable to record the start time
- unsigned long attuale=0; //Variable to record the start time
- unsigned long endTime=0; //Variable to record the end time
- unsigned long signalDuration=0; //Variable to record signal reading time
- int contatore;
- int lettura[50];
- int letbin[50];
- int ver =2;
- void setup() {
- pinMode(ver,OUTPUT);
- contatore=0;
- Serial.begin(9600);
- Serial.println("inizio");
- while(analogRead(rfReceivePin)<1){
- //Wait here until a LOW signal is received
- //startTime=micros(); //Update start time with every cycle.
- // startTime=(startTime+300);
- }
- startTime=micros(); //Update start time with every cycle.
- startTime=(startTime+2734);
- }
- void loop() {
- attuale=micros();
- if (attuale>=startTime){
- contatore=(contatore+1);
- digitalWrite(ver, HIGH);
- lettura[contatore]=(analogRead(rfReceivePin));
- digitalWrite(ver,LOW);
- startTime=(startTime+496);
- }
- if(contatore==49){
- Serial.println("FINITO");
- for (int i=1; i <= 48; i++){
- if (lettura[i]>= 200){
- letbin[i]=1;
- Serial.print("1");
- }
- //Serial.print(lettura[i]);
- //Serial.print(" ");
- if (lettura[i]<= 200){
- letbin[i]=0;
- Serial.print("0");
- }
- }
- //////in Binario
- Serial.println(" ");
- for (int h=1; h <= 48; h++){
- Serial.print(letbin[h]);
- }
- //////////////
- ////STAMPA CODICE /////////////////////////
- Serial.println("");
- int cifra1=((letbin[14]*8)+(letbin[15]*4)+(letbin[16]*2)+(letbin[17]*1));
- Serial.print(cifra1,HEX);
- Serial.print(" ");
- int cifra2=((letbin[18]*8)+(letbin[19]*4)+(letbin[20]*2)+(letbin[21]*1));
- Serial.print(cifra2,HEX);
- Serial.print(" ");
- int cifra3=((letbin[23]*8)+(letbin[24]*4)+(letbin[25]*2)+(letbin[26]*1));
- Serial.print(cifra3,HEX);
- Serial.print(" ");
- int cifra4=((letbin[27]*8)+(letbin[28]*4)+(letbin[29]*2)+(letbin[30]*1));
- Serial.print(cifra4,HEX);
- Serial.print(" ");
- int cifra5=((letbin[32]*8)+(letbin[33]*4)+(letbin[34]*2)+(letbin[35]*1));
- Serial.print(cifra5,HEX);
- Serial.print(" ");
- int cifra6=((letbin[36]*8)+(letbin[37]*4)+(letbin[38]*2)+(letbin[39]*1));
- Serial.print(cifra6,HEX);
- Serial.print(" ");
- ///////////////////////////////////////////
- while(true){}
- }
- }
Add Comment
Please, Sign In to add comment