Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

new to Ardunio but trying to compile

Status
Not open for further replies.
I copied your code to notepad++ and there are no spurious characters.... Weird!!

As I stated above, assuming the original code was copied and pasted.....

The code MrDEB posted here was further copied and pasted from the Arduino IDE, but when he did so, he managed to miss the invisible character at the beginning or end of the code that is causing the error.

If MrDEB copies the code posted here, ensuring he only copies from first character to last and nothing more, it is almost certain to work (well, not have the /stray error....looks like a required library is missing too).
 
Would it not be more reliable if MrDEB just saved the file from the Arduino IDE and attached that to a post ?

Les.
 
here is an edited code that I found on an "instructuable "site. I edited it for correct pins etc.
it looks the same as post 1 but it compiles and runs.
Code:
#include <IRremote.h>

int IRPIN = 11;

IRrecv irrecv(IRPIN);

decode_results result;

void setup()
{
  Serial.begin(9600);

  irrecv.enableIRIn();

}

void loop()
{
  if (irrecv.decode(&result))
  {
    Serial.println(result.value);
    irrecv.resume();
  }
  delay(10);
}
 
here is the code from the instructiable site. as you can see it is basically the same except I omited the HEX and changed the pin# I am just getting 10 digit numbers. The HEX didn't output anything on some buttons?
Code:
#include <IRremote.h>

int IRPIN = 2;

IRrecv irrecv(IRPIN);

decode_results result;

void setup()
{
  Serial.begin(9600);
  Serial.println("Enabling IRin");
  irrecv.enableIRIn();
  Serial.println("Enabled IRin");
}

void loop()
{
  if (irrecv.decode(&result))
  {
    Serial.println(result.value, HEX);
    irrecv.resume();
  }
  delay(500);
}

}
 
Ummm. What do you expect the output to be?

When you press a given button, you should get the same code every time.

Why did you remove the HEX? Do you know why it's there?
 
the value should be 32 bit and negative.... something like 0xFFED78BD... This will be different for each button..


here is the code from the instructiable site. as you can see it is basically the same except I omited the HEX and changed the pin# I am just getting 10 digit numbers. The HEX didn't output anything on some buttons?

It WOULD have output hex numbers, until he "omited (sic) the HEX".....
 
am wanting to be able to point a remote at the ir receiver and the code is saved in the eeprpm.

the Ardunio cook book has an example on doing this but the code has errors. The book has what appears to be typo errors. An I looks like an L but has an extra line. ( an L but with half of a T on top)
Have typed in the code as per book but has a compiller error concerning a missing delecration I assume.
line 16 says it is not in the scope of code.
Code:
#include <IRremote.h>
const int irReceivePin = 11;
const int LedPin = 9;
const int numberOfkeys = 5;
long irKeyCodes[numberOfkeys];
IRrecv irrecv(irReceivePin);
decode_results results;



void setup() {
  Serial.begin(9600);
  pinMode(irReceivePin, INPUT);
  pinMode(LedPin, OUTPUT);
  irrecv.enableIRIn();
  IearnKeycodes();         // here is hang up


  Serial.println("Press a Remote key");
}
void loop()
{
  long key;
  int brightness;
  if (irrecv.decode(&results))

  {
    //if data received
    {
      irrecv.resume();
      key = convertCodeToKey(results.value);
      if (key >= 0)
      {
        Serial.print("got key");
        Serial.println(key);
        brightness = map(Key, 0, numberOfKeys - 1, 0, 255);
        analogWrite(LedPin, brightness);
      }
    }
  }
  void LearnKeycodes()
  {
    while (irrecv.decode(&results))
      irrecv.resume();
    Serial.println("Ready to learn remote codes");
    Long prevValue = -1;
    int L = 0;
    while (L < numberOfKeys)
    {
      Serial.print("press remote ley");
      Serial.print(L);
      while (true)
      {
        if (irrecv.decode(&results))
        {
          if (results.value != -1 &&
              results.decode_type != UNKNOWEN &&
              results.value != prevValue)
          {
            showReceivedData();
            Serial.printLn(results.value);
            irKeyCodes[L] = results.value;
            I = I + 1;
            prevValue = results.value;
            irrecv; .resume();
            break;
          }
          irrecv.resume();
        }
      }
    }
    Serial.printing("learning complete");
  }
  int convertCodeToKey(long code)
  {
    for (int i = 0; i < numberOfKeys; i++)
    {
      If(code == irKeyCodes[i])
      {
        return I;
      }
    }
    return -1
  }
  void showReceivedData()
  {
    if (results.decode_type == UNKNOWEN)
    {
      Serial.printin("COULD NOT DECODE MESSAGE");
    }
    else
    {
      If (results.decode_type == NEC) {
        Serial.print("decoded NEC;")
      }
      else If (results.decode_type == SONY) {
        Serial.print("decoded sony:");
      }
      else If (results.decode_type == RC5) {
        Serial.print("decoded RC5");
      }
      else If (results.decode_type == RC6) {
        Serial.print("decoded RC6");
      }
      Serial.print("hex value=");
      Serial.printin(results.value, HEX);
    }
  }
 
am wanting to be able to point a remote at the ir receiver and the code is saved in the eeprpm.

the Ardunio cook book has an example on doing this but the code has errors. The book has what appears to be typo errors. An I looks like an L but has an extra line. ( an L but with half of a T on top)

It's a capital 'I' instead of an L (or lowercase l) - it's hardly a difficult typo to spot.
 
You really don't have an aptitude for this do you? Fix the typo.

The error line is calling a subroutine.

Screenshot_20210115-112504_Edge.jpg
 
Mr DEB

Here is your IR Remote Code .. ..

C:
#include <IRremote.h>
const int irReceivePin = 11;
const int LedPin = 9;
const int numberOfKeys = 5;
long irKeyCodes[numberOfKeys];
IRrecv irrecv(irReceivePin);
decode_results results;



void setup() {
  Serial.begin(9600);
  pinMode(irReceivePin, INPUT);
  pinMode(LedPin, OUTPUT);
  irrecv.enableIRIn();
  learnKeycodes();         // here is hang up


  Serial.println("Press a Remote key");
}
void loop()
{
  long key;
  int brightness;
  if (irrecv.decode(&results))

  {
    //if data received
    {
      irrecv.resume();
      key = convertCodeToKey(results.value);
      if (key >= 0)
      {
        Serial.print("got key");
        Serial.println(key);
        brightness = map(key, 0, numberOfKeys - 1, 0, 255);
        analogWrite(LedPin, brightness);
      }
    }
  }
}
  void learnKeycodes()
  {
    while (irrecv.decode(&results))
      irrecv.resume();
    Serial.println("Ready to learn remote codes");
    long prevValue = -1;
    int i = 0;
    while (i < numberOfKeys)
    {
      Serial.print("press remote key");
      Serial.print(i);
      while (true)
      {
        if (irrecv.decode(&results))
        {
          if (results.value != -1 &&
              results.decode_type != UNKNOWN &&
              results.value != prevValue)
          {
            showReceivedData();
   //         Serial.printLn(results.value);
            irKeyCodes[i] = results.value;
            i = i + 1;
            prevValue = results.value;
            irrecv.resume();
            break;
          }
          irrecv.resume();
        }
      }
    }
    Serial.println("learning complete");
  }
  int convertCodeToKey(long code)
  {
    for (int i = 0; i < numberOfKeys; i++)
    {
      if(code == irKeyCodes[i])
      {
        return i;
      }
    }
    return -1;
  }
  void showReceivedData()
  {
    if (results.decode_type == UNKNOWN)
    {
      Serial.println("COULD NOT DECODE MESSAGE");
    }
    else
    {
      if (results.decode_type == NEC) {
        Serial.print("decoded NEC;");
      }
      else if (results.decode_type == SONY) {
        Serial.print("decoded sony:");
      }
      else if (results.decode_type == RC5) {
        Serial.print("decoded RC5");
      }
      else if (results.decode_type == RC6) {
        Serial.print("decoded RC6");
      }
      Serial.print("hex value=");
      Serial.println(results.value, HEX);
    }
  }

It compiles OK for a number of reasons.

I don't wish to give the self appointed critics society more ammunition to throw at you; I suggest you print off a copy of your code & a copy of mine and compare the two .. you will find a large number of simple errors corrected.

I hope that helps you

MM
 
yes I have been comparing lots of code lately.
did not know it was calling a sub route.
I downloaded the notebook++ but need to figure out how to use it.
As for the typo, never saw an L with an extra tail as per book
 
Hi

The L with an extra tail is just a lower case L .. Arduino uses a different typeface;
You also confused I and lower case I ;

Print them and compare, you'll see what I mean .. ..


MM
 
I printed and compared. yes a few differences.
program works pretty good but I need to change a few things like add a SWITCH CASE routine
I only need to monitor three switches and I don't think including HEX will make a difference.
The book I am reading has yet to get to sub routines LEARN ADRUNIO IN 24 HOURS
after I get my new work bench set up will be going further with my project.
Still looking at using a pic for this project but looking at both options.
 
You've allegedly been programming for over 10 years and you don't know what a subroutine is? How is that possible?

Mike.
 
You've allegedly been programming for over 10 years and you don't know what a subroutine is? How is that possible?

Mike.
You better look at his swordfish code... All subroutines were included, so invisible to him... We'll have to teach him procedural programming
 
You better look at his swordfish code... All subroutines were included, so invisible to him... We'll have to teach him procedural programming

Excuse me? As in all (most?) implementations of Basic, Swordfish uses subroutines. MrDEB has often used them, calling them "sub routes" because what's a few letters when it comes to programming.

I think MrDEB's comment was about understanding the syntax of subroutines.

Perhaps you are thinking of include files? Swordfish also has those, but beyond those included when you install the program, there aren't too many others. There's no library manager like Arduino has, with thousands of includes available to be added.
 
You've allegedly been programming for over 10 years and you don't know what a subroutine is? How is that possible?

Mike.

He doesn't understand about capital letters, or the differences between different letters either - what chance he knows about sub-routines? (although to be fair they are functions or procedures, not sub-routines :D ).
 
I was referring to post #31. Learnkeycodes. Arduino has different coding practices like capital letters and different type facing as musicmanager pointed out. Post #34.
I have found using an actual book on Arduino has helped some but I like Swordfish. Hopefully try out the Swordfish example about reading an IR remote See https://www.electro-tech-online.com/threads/a-remote-control-using-a-pic.160501/post-1393100. Then decide which path to take.
As far as programming abilities, Have not had any schooling in the subject. Most all by trial and lots of errors. And I don't do programming on a daily basis except when it is raining outside and/or to cold. I enjoy a challenge.
That's one of the reasons I play chess online almost every day. The challenge
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top