Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Last active December 21, 2015 15:28
Show Gist options
  • Save NalaGinrut/6326373 to your computer and use it in GitHub Desktop.
Save NalaGinrut/6326373 to your computer and use it in GitHub Desktop.
String sStart = "1111111110000000000";
String sStop = "0";
int data_to_spoof[64];
int coil_pin = 9; // we use 9th pin
int a,b,c,d;
unsigned long id;
char hex_code[8];
void setup()
{
// Serial.begin(9600);
pinMode(coil_pin, OUTPUT);
digitalWrite(coil_pin, LOW);
id = 0x503472;
a=0;b=0;c=0;d=0;
sprintf(hex_code, "%04X%04X",id);
String s = sStart + em4x_code(hex_code[4]) + em4x_code(hex_code[5])
+ em4x_code(hex_code[6]) + em4x_code(hex_code[7]) + em4x_code(hex_code[0])
+ em4x_code(hex_code[1]) + em4x_code(hex_code[2]) + em4x_code(hex_code[3])
+ even_parity(a) + even_parity(b) + even_parity(c) + even_parity(d) + sStop;
// Serial.println(s);
to_code(s);
loop();
}
void set_pin_manchester(int clock_half, int signal)
{
int man_encoded = clock_half ^ signal;
if(man_encoded == 1)
{
digitalWrite(coil_pin, HIGH);
}
else
{
digitalWrite(coil_pin, LOW);
}
}
String em4x_code(char code)
{
switch (code)
{
case '1': d++; return "00011";
case '2': c++; return "00101";
case '3': c++;d++; return "00110";
case '4': b++; return "01001";
case '5': b++;d++; return "01010";
case '6': b++;c++; return "01100";
case '7': b++;c++;d++; return "01111";
case '8': a++; return "10001";
case '9': a++;d++; return "10010";
case 'A': a++;c++; return "10100";
case 'B': a++;c++;d++; return "10111";
case 'C': a++;b++; return "11000";
case 'D': a++;b++;d++; return "11011";
case 'E': a++;b++;c++; return "11101";
case 'F': a++;b++;c++;d++; return "11110";
}
return "00000";
}
String even_parity(int p)
{
if (p % 2)
return "1";
return "0";
}
void to_code(String s)
{
for(int i = 0; i < 64; i++)
{
if (s[i]=='0'){data_to_spoof[i]=0;}else{data_to_spoof[i]=1;}
}
}
void loop()
{
for(int i = 0; i < 64; i++)
{
set_pin_manchester(0, data_to_spoof[i]);
delayMicroseconds(256);
set_pin_manchester(1, data_to_spoof[i]);
delayMicroseconds(256);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment