Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SCANNER CODIFICA CAME
- #include <VirtualWire.h>
- int a,z; // binary conversion of "a"
- int complement; //zero complement loop for 10 bit
- int combination; // 1023 possible combination
- int longchaine; // length of the chain
- int output = 13; // output to the 433Mhz transmitter
- int buzzer = 5; // output to the buzzer, sounds at each test of 1023 codes
- int a600,a300; // frequence
- int bitframe; // sending number of the bit frame (3 times)
- String bite = "";
- void setup()
- {
- pinMode(output,OUTPUT);
- a600 = 593; // 600µs
- a300 = 292; // 300µs
- longchaine=0;
- Serial.begin(9600);
- }
- void loop()
- {
- // Buzzer 1 bip
- tone(buzzer, 1000, 500);
- combination=0;
- for (combination=0; combination<1024;combination++){
- String a = String(combination, BIN);// conversion en binaire de "a"
- longchaine=a.length(); // longueur de la chaine "a"
- //boucle de complement de "0" pour avoir 10 bits
- complement=0;
- for (complement=0; complement<(10-longchaine);){
- a="0"+a;
- complement++;
- }
- // number of send of bitframe
- for (int bitframe = 0; bitframe < 3; bitframe++)
- {
- // BIT start 0
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- digitalWrite(output, HIGH); // 5v
- delayMicroseconds(a300); // 600µs
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- // assignment of the 10 bits to the variable "bite"
- z=0;
- for (z=0; z<(10);){
- bite = (a.substring(z+1,z)); // extraction des bits
- if (bite=="0"){
- // BIT 0
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- digitalWrite(output, HIGH); // 5v
- delayMicroseconds(a300); // 600µs
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- }
- else {
- // BIT 1
- digitalWrite(output, HIGH); // 5v
- delayMicroseconds(a600); // 600µs
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- }
- z++;
- }
- // final bit 0
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- digitalWrite(output, HIGH); // 5v
- delayMicroseconds(a300); // 600µs
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- // final bit 1
- digitalWrite(output, HIGH); // 5v
- delayMicroseconds(a600); // 600µs
- digitalWrite(output, LOW); // 0v
- delayMicroseconds(a300); // 300µs
- delay(12); // interval between bitframe
- }
- delay(1000); // interval between combination code
- Serial.println(combination);
- }
- // Buzzer 2 bip
- tone(buzzer, 2000, 500);
- delay(550);
- tone(buzzer, 2000, 500);
- delay(1500); // pause time 1,5s after ending loop
- }
Advertisement
Add Comment
Please, Sign In to add comment