amp not declared in this scope...totally stuck, total noob, please help

#include <IRremote.h>
#define irPin 7

IRrecv irrecv(irPin);
decode_results results;

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {

  if (irrecv.decode(&amp; results))
    Serial.println(results.value);

  switch (results.value) {

    case 16718055:            // button 2 FORDWARD
      forward();
      break;

    case 16716015:            // button 4 LEFT
      left();
      break;

    case 16726215:            // button 5 STOP
      Stop();
      break;

    case 16734885:            // button 6 RIGHT
      right();
      break;

    case 16730805:            // button 8 BACK
      back();
      break;


  }
  irrecv.resume();
}
}

void forward()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
}

void back()
{
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
}

void left()
{
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
}

void right()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
}

void Stop()
{
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
}

Arduino: 1.8.13 (Windows 10), TD: 1.53, Board: "Arduino Nano, ATmega328P"

C:\Users\duncan\Documents\Arduino\car_ir\car_ir.ino: In function 'void loop()':

car_ir:19:22: error: 'amp' was not declared in this scope

if (irrecv.decode(& results))

^~~

car_ir:19:25: error: expected ')' before ';' token

if (irrecv.decode(& results))

^

car_ir:19:34: error: expected ';' before ')' token

if (irrecv.decode(& results))

^

car_ir:25:7: error: 'forward' was not declared in this scope

forward();

^~~~~~~

C:\Users\duncan\Documents\Arduino\car_ir\car_ir.ino:25:7: note: suggested alternative: 'fread'

forward();

^~~~~~~

fread

car_ir:29:7: error: 'left' was not declared in this scope

left();

^~~~

car_ir:33:7: error: 'Stop' was not declared in this scope

Stop();

^~~~

C:\Users\duncan\Documents\Arduino\car_ir\car_ir.ino:33:7: note: suggested alternative: 'loop'

Stop();

^~~~

loop

car_ir:37:7: error: 'right' was not declared in this scope

right();

^~~~~

car_ir:41:7: error: 'back' was not declared in this scope

back();

^~~~

C:\Users\duncan\Documents\Arduino\car_ir\car_ir.ino: At global scope:

car_ir:48:1: error: expected declaration before '}' token

}

^

Multiple libraries were found for "IRremote.h"

Used: C:\Users\duncan\Documents\Arduino\libraries\IRremote

Not used: C:\Users\duncan\Documents\Arduino\libraries\Arduino-IRremote-master

exit status 1

'amp' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

ive tried a few suggestions ive found in the forum but nothing seems to work. i know its going to be a fairly simple answer but i just cant seem to sort it. thanks in advance

  irrecv.resume();
}
}

Oops...

And:

  if (irrecv.decode(&amp; results))

is wrong, this is the syntax for this call:

  if (irrecv.decode(&results))

Did you copy this code from the www?

#include <IRremote.h>
#define irPin 7

IRrecv irrecv(irPin);
decode_results results;

void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {

  if (irrecv.decode(&results))
    Serial.println(results.value);

  switch (results.value) {

    case 16718055:            // button 2 FORDWARD
      forward();
      break;

    case 16716015:            // button 4 LEFT
      left();
      break;

    case 16726215:            // button 5 STOP
      Stop();
      break;

    case 16734885:            // button 6 RIGHT
      right();
      break;

    case 16730805:            // button 8 BACK
      back();
      break;


  }
  irrecv.resume();
}


void forward()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
}

void back()
{
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
}

void left()
{
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
}

void right()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
}

void Stop()
{
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
}
&amp;

That looks suspiciously like HTML to me

Where did you copy the code from ?

It should almost certainly be

  if (irrecv.decode(&results))

I've made the changes and the code compiles fine. new issue is it wont actually do anything. everything is wired up as it should be and absolutely nothing happens apart from a flash from the ir receiver when i hit the remote.

tried changing the code to this which again compiles absolutely fine and worked on a previous iteration of the car but on this one nothing works.

#include <IRremote.h>
#define irPin 7

IRrecv irrecv(irPin);
decode_results results;

int enableA = 2;
int pinA1 = 8;
int pinA2 = 9;

int enableB =3;
int pinB1 = 10;
int pinB2 = 11;

void setup() {
  pinMode(enableA, OUTPUT);
  pinMode(pinA1, OUTPUT);
  pinMode(pinA2, OUTPUT);
  pinMode(enableB, OUTPUT);
  pinMode(pinB1, OUTPUT);
  pinMode(pinB2, OUTPUT);

  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  analogWrite(enableA, 100);
  analogWrite(enableB, 100);

  if (irrecv.decode(&results))
    Serial.println(results.value);

  switch (results.value) {

    case 16718055:            // button 2 FORDWARD
      forward();
      break;

    case 16716015:            // button 4 LEFT
      left();
      break;

    case 16726215:            // button 5 STOP
      Stop();
      break;

    case 16734885:            // button 6 RIGHT
      right();
      break;

    case 16730805:            // button 8 BACK
      back();
      break;


  }
  irrecv.resume();
}


void forward()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, LOW);
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, LOW);
}

void back()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, HIGH);
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, HIGH);
}

void left()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, HIGH);
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, LOW);
}

void right()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, LOW);
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, HIGH);
}

void Stop()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, LOW);
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, LOW);
}

probably should just give up and go to bed for now.

all help appreciated

Were those supposed to be hex values or not? i.e. 0x16730805 not 16730805?

aarg:
Were those supposed to be hex values or not? i.e. 0x16730805 not 16730805?

just gave that a go (adding the 0x to each one) but still no effect. its odd because it was all working fine on similar code earlier with an ultrasonic sensor instead of the IR receiver. i might just attempt to put it back the way it was and go from there and make additions to the original code rather than whatever this is that refuses to work.

I read something about a Deprecated Function Call. Check the README file that came with the IR library:

And check your compiler output for a warning like this:
"warning: 'bool IRrecv::decode(decode_results*)' is deprecated: You should use decode() without a parameter. [-Wdeprecated-declarations]"

Erik_Baas:
I read something about a Deprecated Function Call. Check the README file that came with the IR library:

And check yur compiler output for a warning like this:
"warning: 'bool IRrecv::decode(decode_results*)' is deprecated: You should use decode() without a parameter. [-Wdeprecated-declarations]"

I've gone through literally everything i could think of and then some. I've just reverted back to the original code I was using and I'm going to try and add a simple stop function to it using the IR as i had a bit of an incident earlier where the vcc for the ultrasonic sensor came lose and the car didn't detect a pile of bricks and did a fairly impressive back flip ( I was experimenting with notched out CDs as makeshift off road wheels at the time).
original code (im not using the servo so should really delete)

#include <Servo.h>          //standard library for the servo
#include <NewPing.h>        //for the Ultrasonic sensor function library.

//L298N motor control pins
const int enableA = 2;
const int enableB = 3;
const int LeftMotorForward = 8;
const int LeftMotorBackward = 9;
const int RightMotorForward = 10;
const int RightMotorBackward = 11;

//sensor pins
#define trig_pin 7 //digital input 1
#define echo_pin 6 //digital input 2

#define maximum_distance 200
boolean goesForward = false;
int distance = 100;

NewPing sonar(trig_pin, echo_pin, maximum_distance); //sensor function
Servo servo_motor; 

void setup(){

  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);
  
  servo_motor.attach(13); //our servo pin

  servo_motor.write(115);
  delay(2000);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
  distance = readPing();
  delay(100);
}

void loop(){

  int distanceRight = 0;
  int distanceLeft = 0;
  delay(50);

  if (distance <= 80){
    moveStop();
    delay(100);
    moveBackward();
    delay(1000);
    moveStop();
    delay(150);
    distanceRight = lookRight();
    delay(300);
    distanceLeft = lookLeft();
    delay(300);

    if (distance >= distanceLeft){
      turnRight();
      moveStop();
    }
    else{
      turnLeft();
      moveStop();
    }
  }
  else{
    moveForward(); 
  }
    distance = readPing();
}

int lookRight(){  
  servo_motor.write(50);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
}

int lookLeft(){
  servo_motor.write(170);
  delay(500);
  int distance = readPing();
  delay(100);
  servo_motor.write(115);
  return distance;
  delay(100);
}

int readPing(){
  delay(70);
  int cm = sonar.ping_cm();
  if (cm==0){
    cm=250;
  }
  return cm;
}

void moveStop(){
  
  digitalWrite(RightMotorForward, LOW);
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);
  digitalWrite(LeftMotorBackward, LOW);
}

void moveForward(){

  if(!goesForward){

    goesForward=true;
    
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(RightMotorForward, HIGH);
  
    digitalWrite(LeftMotorBackward, LOW);
    digitalWrite(RightMotorBackward, LOW); 
  }
}

void moveBackward(){

  goesForward=false;

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
}

void turnRight(){

  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorBackward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorForward, LOW);
  
  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
 
  
  
}

void turnLeft(){

  digitalWrite(LeftMotorBackward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorForward, LOW);
  digitalWrite(RightMotorBackward, LOW);

  delay(500);
  
  digitalWrite(LeftMotorForward, HIGH);
  digitalWrite(RightMotorForward, HIGH);
  
  digitalWrite(LeftMotorBackward, LOW);
  digitalWrite(RightMotorBackward, LOW);
}

I believe analogWrite(...) is not supported for pin 2 on the Nano (or Uno).

Blackfin:
I believe analogWrite(...) is not supported for pin 2 on the Nano (or Uno).

wasn't aware of that, I've moved back to the second code i posted in my later comment now and its up and running just doesn't have the desired IR functions yet but hopefully ill work out how to get them in some point tomorrow. I'm hoping once i have that done i can work out how to add 2 more ultrasonic sensors but I'm thinking ill probably have to change up to a mega as I'm running out of pins to use and i still have to add led's and possibly a buzzer. once I've got it setup how I want it ill post a few pics, its already looking pretty unique.

You can learn which pins are compatible with analogWrite() by checking the reference page for that function:

pert:
You can learn which pins are compatible with analogWrite() by checking the reference page for that function:
analogWrite() - Arduino Reference

thanks :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.