Building a Diet Coke Remote control - way better than a button.

Not to be shown up by any former world leaders with a diet coke button... I'm building a Diet Coke Button.

Basically, push a button and play a message on LCD. Possibly play a little tune on a passive buzzer. Everything is wired up fine for both the lcd and the IR sensor... I have it set to display the hex for the remote code on the serial monitor... I'm just having trouble figuring out what to do to get everything working together... uncommenting the lcd code throws various errors, and I also can't get it to print a string to the serial monitor, aside from the hex code for the button, of course... the code:

#include <IRremote.h>
#include <LiquidCrystal.h>
int rs = 7;
int en = 8;
int d4 = 9;
int d5 = 10;
int d6 = 11;
int d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int IRpin = 3;
IRrecv IR (IRpin);
decode_results cmd;
String myCom;
void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);
  IR.enableIRIn();
}
void loop() {
  while (IR.decode(&cmd) == 0) {
  }
  Serial.println(cmd.value, HEX);
  IR.resume();
}
Serial.println(cmd.value, HEX);
if (cmd.value == 0xFF6897) {
  Serial.println("Bring Diet Coke");
}
lcd.setCursor(0, 0);
lcd.print("");
delay(1000);
}

Hello Nick,
Welcome.
Please can you read the forum guidelines then go back and edit your post to give people a chance of helping you. How to get the best out of this forum - Introductory Tutorials - Arduino Forum

Specifically
Post your code in code tags </> after properly formatting it in the IDE
Explain better what you have and show a schematic. You mention pressing a button but your code does not seem to read a button it seems to read some kind of unspecified IR device you've not told us about.
You mention errors but don't tell us what they are, that too is mentioned in the tutorial.

When you are comparing to a hex number you have to prefix it by 0x to indicate a hex number.

Like this:

if (cmd.value == 0xFF6897){

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Ah, I'm working on the formatting thing. I'm more into web dev than compiled languages. I love white space because of how my brain works. I just got my mega 2560 kit and have otherwise not used c++ for much. My current PC build can now run unreal engine projects, but I digress.

#include <IRremote.h>
#include <LiquidCrystal.h>

int rs = 7;
int en = 8;
int d4 = 9;
int d5 = 10;
int d6 = 11;
int d7 = 12;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int IRpin = 3;
IRrecv IR (IRpin);
decode_results cmd;

String myCom;

void setup()
{
   lcd.begin(16, 2);

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

void loop()
{
   while (IR.decode(&cmd) == 0)
   {
   }
   Serial.println(cmd.value, HEX);
   IR.resume();
}

Serial.println(cmd.value, HEX);
if (cmd.value == FF6897) 
{
   Serial.println("Bring Diet Coke");

}

lcd.setCursor(0, 0);
lcd.print("");
delay(1000);
}

Here is your code with the useless white space removed. All that white space makes the code very hard for me to follow. And the IDE autoformat tool (ctrl-t or Tools, Auto Format) applied (and posted in code tags). Note that the line

Serial.println(cmd.value, HEX);

is all the way to the left margin. That puts that line and all subsequent lines outside of the loop() function, thus an error. The } above that line is out of place and closes the loop() function early. Here is the corrected code that does compile.

#include <IRremote.h>
#include <LiquidCrystal.h>

int rs = 7;
int en = 8;
int d4 = 9;
int d5 = 10;
int d6 = 11;
int d7 = 12;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int IRpin = 3;
IRrecv IR (IRpin);
decode_results cmd;

String myCom;

void setup()
{
   lcd.begin(16, 2);

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

void loop()
{
   while (IR.decode(&cmd) == 0)
   {
   }
   Serial.println(cmd.value, HEX);
   IR.resume();
   // }    **********  misplaced } closes loop() function

   Serial.println(cmd.value, HEX);
   if (cmd.value == 0xFF6897)  // *********** 0x the required hex prefix.
   {
      Serial.println("Bring Diet Coke");

   }

   lcd.setCursor(0, 0);
   lcd.print("");
   delay(1000);
}

Well that same white space makes the code very hard for me to follow.

Ahhhh, the margin thing was bothering me, too. IDK if you guys are familiar with Paul McWhorter on Youtube. He seems pretty informative. He's apparently a math teacher. This code is partially some of his codes stuck together with some other stuff.

On a small side note, that code compiled when changing "cmd.value == FF6897" to "cmd.value == 0xFF6897", naturally. Because of the hex thing.

I love white space because of how my brain works

I couldn’t resist highlighting this sentence !

To elaborate, my brain is geared towards spatial awareness... There's an entire esoteric programming language that is all whitespace.

No offence intended, it was just very intriguing...
From that link...

Unlike most programming languages, which ignore or assign little meaning to most whitespace characters, the Whitespace interpreter ignores any non-whitespace characters.

An interesting proposition...
I’m intrigued by the possibilities, but couldn’t avoid noticing it was launched on ‘April Fools Day’ (!)

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