Simple Script returning an error

Hi all, I'm pretty experienced in web programming but very new to arduino. I'm trying to play with it to send out an IR command to interact with some candles.

THe code is below (pretty much copied exactly from a tutorial online) however I get an error message and I don't understand why, or how to fix? Any help appreciated, thanks!

#include <IRremote.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

int reciever = 11;
char buttonState = LOW;
#define button 12
#define LED 13
#define StatusLED 8
//IRrecv irrecv(reciever); // disabled
IRsend irsend();
decode_results results;

void setup(){
Serial.begin(9600);
//irrecv.enableIRIn(); // disabled
pinMode(button, INPUT_PULLUP);
pinMode(LED, OUTPUT);
pinMode(StatusLED, OUTPUT);
digitalWrite(StatusLED, HIGH);
delay(500);
digitalWrite(StatusLED, LOW);
delay(500);
digitalWrite(StatusLED, HIGH);
delay(500);
digitalWrite(StatusLED, LOW);
delay(500);
}
void loop(){
buttonState = digitalRead(button);
if (digitalRead(button) == LOW){
Serial.println("Button Low");
digitalWrite(StatusLED, HIGH);
for (int i = 0; i < 3; i++){
irsend.sendNEC(0x1FE20DF, 32);
delay(40);
}
delay(1000);

}else{
Serial.println("Button High");
digitalWrite(StatusLED, LOW);
}
/*
if (irrecv.decode(&results)){ // disabled
Serial.println(results.value, HEX); // disabled
irrecv.resume(); // disabled
} // disabled
*/
}

/*Candle Commands

  • 1FE48B7 - ON
  • 1FE58A7 - OFF
  • 1FE20DF - RED
  • 1FE30CF - WHITE
  • 1FE7887 - MODE

*/

ERROR when compiling:

Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Uno"

C:\Users\natha\OneDrive\ARDUINO\Projects\IR Receiver\Reciever_get_signals___TRANSMIT_RED_Candle\Reciever_get_signals___TRANSMIT_RED_Candle.ino: In function 'void loop()':

Reciever_get_signals___TRANSMIT_RED_Candle:35:12: error: request for member 'sendNEC' in 'irsend', which is of non-class type 'IRsend()'

irsend.sendNEC(0x1FE20DF, 32);

^~~~~~~

exit status 1

request for member 'sendNEC' in 'irsend', which is of non-class type 'IRsend()'

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

Probably something really simple. but thank you in advance of any replies!

IRsend irsend(); is the declaration of a function “irsend” that takes no parameters and returns an object of type IRsend. Remove the parentheses if you want to instantiate an object of type IRsend.

Pieter

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Also in the IDE, Press CTRL T and it will format the detents for you.
I assume you are using a UNO?

Thanks.. Tom.. :slight_smile:

Thanks guys - removed the parenthesis from the irsend. Think it confused / caught me out because the irrecv one requires a port number in the parenthesis.

On the downside I accidentally wired up my reciever wires backwards and I think I just fried my board... whoops!

If you use braces for initialization you don't have to worry about it:

IRsend irsend { port_number };
IRsend irsend {};

Thanks :slight_smile:

Just to confirm I am on the right lines as far as formatting goes... would I be correct in thinking IRsend is the library function.... so the line is effectively saying load IRsend and name it as irsend (so irsend could be renamed but IRsend cannot?)

Cheers

No, IRsend is a type name, it names a class. You create an instance of that class and give it a name, irsend.