I am doing a project with a receiver and transmitter and i am trying to get a message to print onto the screen. If anybody has any experience with this could you please help! I am trying to use a switch case command and it's not working. Edit:
`
#include <LiquidCrystal.h>
#include <VirtualWire.h>
LiquidCrystal lcd(12, 8, 5, 4, 3, 2);
byte message[VW_MAX_MESSAGE_LEN]; // a buffer to store the incoming messages
byte messageLength = VW_MAX_MESSAGE_LEN; // the size of the message
void setup()
{
Serial.begin(9600);
Serial.println("Device is ready");
// Initialize the IO and ISR
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver
lcd.begin(16, 2);
// Print a message to the LCD.
}
void loop()
{
if (vw_get_message(message, &messageLength)) // Non-blocking
{
switch(message[1])
{
case 0:
lcd.setCursor(0, 1);
lcd.print("O.O");
break;
case 1 :
lcd.setCursor(0, 1);
lcd.print("Hi! :)");
break;
}
{
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++)
{
Serial.write(message[i]);
}
Serial.println();
}
}
}
-
Show what you've tried.dinotom– dinotom2016年05月11日 19:21:12 +00:00Commented May 11, 2016 at 19:21
-
Ive changed my code so many times so far, but at this moment it is:ArduinoGrl45– ArduinoGrl452016年05月11日 19:27:09 +00:00Commented May 11, 2016 at 19:27
-
1Okay! I finally got my code to post correctly!ArduinoGrl45– ArduinoGrl452016年05月11日 19:37:34 +00:00Commented May 11, 2016 at 19:37
-
Please read How do I ask a good question?. You have described what you want. Now tell us what happens, and compare that to what you expected to happen.Nick Gammon– Nick Gammon ♦2016年05月20日 06:09:21 +00:00Commented May 20, 2016 at 6:09
1 Answer 1
Too many pieces of the puzzle are missing for us to venture a guess on what is going wrong:
The output you get (both in the LCD and the serial console)
The message sent
One thing that strikes me as a potential problem is the
switch(message[1])
line. If you want to check the first character received, it should be
switch(message[0])
That said, it would perhaps help you if you tried to split the program into pieces and make sure each one works before advancing to the next. Are you sure the LCD pin connections and initialisation line match? (I know from experience it is very easy to mess up and put the pin numbers in the wrong order). It would help to put the following code right after the lcd.begin line (in your setup() function):
lcd.setCursor(0, 0);
lcd.print("Initialised!");
Now if this line doesn't display correctly, you will know it is the lcd connection/initialisation code that is at fault. Otherwise, you will concentrate on your communication code.
Give us more information and we 'll be able to help more.