I need to reproduce with a digital pin of an Arduino such a key in the form of a sequence of 1's and 0's, where a one takes 2 ms high and 2 ms low, and a zero takes 1 ms high and 1 ms low.
int key = 0b101100001111;
void setup()
{
pinMode(13, OUTPUT);
}
void loop()
{
for (int n = 0; n < 12; n++)
{
if (bitRead(key, n) == 1) //execute if bit value == 1
{
sendSignal(2000);
}
else //execute if bit value == 0
{
sendSignal(1000);
}
}
}
void sendSignal(int duration)
{
digitalWrite(13, HIGH);
delayMicroseconds(duration);
digitalWrite(13, LOW);
delayMicroseconds(duration);
}
This sketch really works! I figured out what my problem is: I actually need a longer key (64 bits). I am using long type: long key = 0b1000011110001101111100011111001010110001101101111011011100110100; but long only allows 32 bits. What do you recommend to do? Maybe you need to arrange it as an array? I think you can make it easier somehow. thank you
0b101100001111
can never fit into a byte.