About LCD and Switch

04 Feb 2012

Hello this is my first post and i am beginner in mbed we make a project in which there is RFID reader connected to Rx pin p10 of mbed and lcd i want to read string coming from RFID reader and show it on lcd also compair it with switch statement and if string is ok then just say card vaild on lcd we check RFID reader output on pc which string is 2200BE7D7D my code is as follows

  1. include "mbed.h"
  2. include "TextLCD.h" TextLCD lcd(p26, p25, p5, p6, p7, p8); rs, e, d4-d7 define lcd pin Serial device(p9,p10);tx,rx char buffer_for_incoming_message[10]; creates buffer for message with max length 30 charac

int main() { lcd.printf("Hello" ); lcd.locate(0,1); lcd.printf("Word "); wait(2); lcd.cls();; lcd.printf("Please swap"); lcd.locate(0,1); lcd.printf("the Card"); device.baud(9600); wait(1); lcd.cls(); while(1) {

if (device.readable()){ If pc is readable device.scanf("%s", &buffer_for_incoming_message); each turn reads message from pc and lcd.printf(&buffer_for_incoming_message); switch(&buffer_for_incoming_message) case 2200BE7D7D:lc.printf("Card is valid); } } }

but it does not work please help me how to write string on lcd and about switch function

04 Feb 2012

Can you repost your code using '<<code>>' and '<</code>>' tags to make it a bit easier to read?

From a quick look you have only reserved 10 bytes for the array but say it should hold 30 characters. How far are you getting? Does anything appear on the screen?

04 Feb 2012

I think what you're trying to do is something like this:

...

while (1) {
  if (device.readable()){ // If pc is readable
    device.scanf("%s", &buffer_for_incoming_message); // each turn reads message from pc 

    lcd.printf(&buffer_for_incoming_message);
  
    switch(&buffer_for_incoming_message) {
      case 2200BE7D7D: lcd.printf("Card is valid);
    }
  }
}

There are some smaller problems here, but biggest mistake is that switch can not deal with strings. It only accepts integers.

You need to use string compare functions and use if tests:

if (strcmp (buffer_for_incoming_message, "2200BE7D7D") == 0) {
 //strings are equal
 lcd.printf("Card is valid");
}

checkout http://www.cplusplus.com/reference/clibrary/cstring/strcmp/

05 Feb 2012

yes strings com pair ok my code is same just you retype But how we write string on lcd lcd.printf(&buffer_for_incoming_message); is not working

05 Feb 2012

I think you need sompthing like this ...

LCD.printf ("some generated text .. %s",buffer-for-incoming-text) ;

Note the %s is a STANDARD C string, same as %4.2f will print a floating point number, and %04X will print a 16 bit HEX, number (in upper case)

Hope this helps

Ceri.