hardweb-it

Scanner CAME

Jul 3rd, 2018
859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.91 KB | None | 0 0
  1. // SCANNER CODIFICA CAME
  2.  
  3. #include <VirtualWire.h>
  4.  
  5. int a,z; // binary conversion of "a"
  6. int complement; //zero complement loop for 10 bit
  7. int combination; // 1023 possible combination
  8. int longchaine; // length of the chain
  9. int output = 13; // output to the 433Mhz transmitter
  10. int buzzer = 5; // output to the buzzer, sounds at each test of 1023 codes
  11. int a600,a300; // frequence
  12. int bitframe; // sending number of the bit frame (3 times)
  13.  
  14. String bite = "";
  15.  
  16. void setup()
  17. {
  18.   pinMode(output,OUTPUT);  
  19.   a600 = 593; // 600µs
  20.   a300 = 292; // 300µs  
  21.   longchaine=0;
  22.   Serial.begin(9600);
  23. }
  24.  
  25. void loop()
  26. {
  27.   // Buzzer 1 bip
  28.   tone(buzzer, 1000, 500);
  29.  
  30.   combination=0;
  31.   for (combination=0; combination<1024;combination++){
  32.     String a =  String(combination, BIN);// conversion en binaire de "a"
  33.     longchaine=a.length(); // longueur de la chaine "a"
  34.    
  35.     //boucle de complement de "0" pour avoir 10 bits
  36.     complement=0;
  37.     for (complement=0; complement<(10-longchaine);){
  38.       a="0"+a;
  39.       complement++;
  40.     }
  41.  
  42.     // number of send of bitframe
  43.      for (int bitframe = 0; bitframe < 3; bitframe++)
  44.     {
  45.       // BIT start 0
  46.       digitalWrite(output, LOW); // 0v
  47.       delayMicroseconds(a300); // 300µs
  48.       digitalWrite(output, HIGH); // 5v
  49.       delayMicroseconds(a300); // 600µs
  50.       digitalWrite(output, LOW); // 0v
  51.       delayMicroseconds(a300); // 300µs
  52.  
  53.       // assignment of the 10 bits to the variable "bite"
  54.         z=0;
  55.       for (z=0; z<(10);){
  56.         bite = (a.substring(z+1,z)); // extraction des bits
  57.         if (bite=="0"){
  58.           // BIT 0
  59.           digitalWrite(output, LOW); // 0v
  60.           delayMicroseconds(a300); // 300µs
  61.           digitalWrite(output, HIGH); // 5v
  62.           delayMicroseconds(a300); // 600µs
  63.           digitalWrite(output, LOW); // 0v
  64.           delayMicroseconds(a300); // 300µs
  65.         }
  66.         else {
  67.           //  BIT 1
  68.           digitalWrite(output, HIGH); // 5v
  69.           delayMicroseconds(a600); // 600µs
  70.           digitalWrite(output, LOW); // 0v
  71.           delayMicroseconds(a300); // 300µs
  72.         }
  73.         z++;
  74.       }
  75.      // final bit 0
  76.         digitalWrite(output, LOW); // 0v
  77.         delayMicroseconds(a300); // 300µs
  78.         digitalWrite(output, HIGH); // 5v
  79.         delayMicroseconds(a300); // 600µs
  80.         digitalWrite(output, LOW); // 0v
  81.         delayMicroseconds(a300); // 300µs
  82.      
  83.       // final bit 1
  84.         digitalWrite(output, HIGH); // 5v
  85.         delayMicroseconds(a600); // 600µs
  86.         digitalWrite(output, LOW); // 0v
  87.         delayMicroseconds(a300); // 300µs  
  88.  
  89.         delay(12); // interval between bitframe
  90.     }  
  91.     delay(1000); // interval between combination code
  92.     Serial.println(combination);
  93.   }
  94.   // Buzzer 2 bip
  95.   tone(buzzer, 2000, 500);
  96.   delay(550);
  97.   tone(buzzer, 2000, 500);
  98.  
  99.   delay(1500); // pause time 1,5s after ending loop
  100. }
Advertisement
Add Comment
Please, Sign In to add comment