Skip to main content

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Also, a byte only can contain 8 bits, you need 12, so make it an int (thanks to ocrdu, see comment below):

int key = 0b101100001111;

If you need more bits, you can use uint32_t or uint64_t, and count further than the current 12.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Also, a byte only can contain 8 bits, you need 12, so make it an int (thanks to ocrdu, see comment below):

int key = 0b101100001111;

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Also, a byte only can contain 8 bits, you need 12, so make it an int (thanks to ocrdu, see comment below):

int key = 0b101100001111;

If you need more bits, you can use uint32_t or uint64_t, and count further than the current 12.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);
added 143 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 43
  • 59

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Also, a byte only can contain 8 bits, you need 12, so make it an int (thanks to ocrdu, see comment below):

int key = 0b101100001111;

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Also, a byte only can contain 8 bits, you need 12, so make it an int (thanks to ocrdu, see comment below):

int key = 0b101100001111;

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);
added 1096 characters in body
Source Link
Michel Keijzers
  • 13k
  • 7
  • 43
  • 59

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

You should make

byte key = 0b101100001111;

global, i.e. put it BEFORE the setup function and not within it.

Now key is a local variable which is removed after exiting the setup function.

I'm not sure where 'key' comes from in:

switch (bitRead(key, n)) {

Do you get a compiler error, or did you ALSO define a global variable named key ? Anyway, if you make key global it will fix either way.

A few other remarks:

  • Try to align your parenthesis, like the 3 }'s at the end, indent them properly, this makes your code much more readable
  • Instead of the switch/case, you could use an if statement in this case, as the re are only (and always) two possible values (0 and 1):

Thus:

 if(bitRead(key, n) == 0)
 {
     ...
 } 
 else // 1
 {
     ...
 }
  • Try also comments to write in English instead of Greek, you never know when your comments will be read by non Greek readers (like now).

  • You can make the following fragment shorter and less duplicated:

Original:

digitalWrite(13, HIGH);
delayMicroseconds(1000);
digitalWrite(13, LOW);
delayMicroseconds(1000);

If you wrap this in a function:

void sendSignal(int duration)
{
    digitalWrite(13, HIGH);
    delayMicroseconds(duration);
    digitalWrite(13, LOW);
    delayMicroseconds(duration);
}

Then you can write a 1 by calling:

sendSignal(2000);

and a 0 by calling:

sendSignal(1000);
Source Link
Michel Keijzers
  • 13k
  • 7
  • 43
  • 59
Loading