types - String to *character arduino -


i want display real time string on nokia 5110 using arduino. found code lcdstring function there takes *character parameter instead of sting. hence when pass string variable it displays

error: cannot convert 'string' 'char' argument '1' 'void lcdstring(char*)'*

here code using

 /* scrolling text example code modified from: http://www.arduino.cc/playground/code/pcd8544 */  string a=""; // pins use on arduino #define pin_sce   7 #define pin_reset 6 #define pin_dc    5 #define pin_sdin  4 #define pin_sclk  3  // configuration lcd #define lcd_c     low #define lcd_d     high #define lcd_cmd   0  // size of lcd #define lcd_x     84 #define lcd_y     48  int scrollposition = -10;  static const byte ascii[][5] = {  {0x00, 0x00, 0x00, 0x00, 0x00} // 20 ,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 ! ,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 " ,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 # ,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $ ,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 % ,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 & ,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 ' ,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 ( ,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 ) ,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a * ,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b + ,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c , ,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d - ,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e . ,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f / ,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0 ,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1 ,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2 ,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3 ,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4 ,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5 ,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6 ,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7 ,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8 ,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9 ,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a : ,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ; ,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c < ,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d = ,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e > ,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ? ,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @ ,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 ,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 b ,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 c ,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 d ,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 e ,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 f ,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 g ,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 h ,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 ,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a j ,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b k ,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c l ,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d m ,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e n ,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f o ,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 p ,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 q ,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 r ,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 s ,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 t ,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 u ,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 v ,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 w ,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 x ,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 y ,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a z ,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [ ,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥ ,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ] ,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^ ,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _ ,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 ` ,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 ,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b ,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c ,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d ,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e ,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f ,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g ,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h ,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 ,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j ,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k ,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l ,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m ,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n ,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o ,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p ,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q ,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r ,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s ,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t ,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u ,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v ,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w ,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x ,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y ,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z ,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b { ,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c | ,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d } ,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ← ,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f → };  void lcdcharacter(char character) {   lcdwrite(lcd_d, 0x00);   (int index = 0; index < 5; index++)   {     lcdwrite(lcd_d, ascii[character - 0x20][index]);   }   lcdwrite(lcd_d, 0x00); }  void lcdclear(void) {   (int index = 0; index < lcd_x * lcd_y / 8; index++)   {     lcdwrite(lcd_d, 0x00);   } }  void lcdinitialise(void) {   pinmode(pin_sce,   output);   pinmode(pin_reset, output);   pinmode(pin_dc,    output);   pinmode(pin_sdin,  output);   pinmode(pin_sclk,  output);    digitalwrite(pin_reset, low);   digitalwrite(pin_reset, high);    lcdwrite(lcd_cmd, 0x21);  // lcd extended commands.   lcdwrite(lcd_cmd, 0xbf);  // set lcd vop (contrast). //b1   lcdwrite(lcd_cmd, 0x04);  // set temp coefficent. //0x04   lcdwrite(lcd_cmd, 0x14);  // lcd bias mode 1:48. //0x13   lcdwrite(lcd_cmd, 0x0c);  // lcd in normal mode. 0x0d inverse   lcdwrite(lcd_c, 0x20);   lcdwrite(lcd_c, 0x0c); }  void lcdstring(char *characters) {   while (*characters)   {     lcdcharacter(*characters++);   } }  void lcdwrite(byte dc, byte data) {   digitalwrite(pin_dc, dc);   digitalwrite(pin_sce, low);   shiftout(pin_sdin, pin_sclk, msbfirst, data);   digitalwrite(pin_sce, high); }  /**  * gotoxy routine position cursor  * x - range: 0 84  * y - range: 0 5  */ void gotoxy(int x, int y) {   lcdwrite( 0, 0x80 | x);  // column.   lcdwrite( 0, 0x40 | y);  // row. }  void drawbox(void) {   int j;   for(j = 0; j < 84; j++) // top   {     gotoxy(j, 0);     lcdwrite(1, 0x01);   }    for(j = 0; j < 84; j++) //bottom   {     gotoxy(j, 5);     lcdwrite(1, 0x80);   }    for(j = 0; j < 6; j++) // right   {     gotoxy(83, j);     lcdwrite(1, 0xff);   }    for(j = 0; j < 6; j++) // left   {     gotoxy(0, j);     lcdwrite(1, 0xff);   } }  void scroll(string message) {   (int = scrollposition; < scrollposition + 11; i++)   {     if ((i >= message.length()) || (i < 0))     {       lcdcharacter(' ');     }     else     {       lcdcharacter(message.charat(i));     }   }   scrollposition++;   if ((scrollposition >= message.length()) && (scrollposition > 0))   {     scrollposition = -10;   } }  void setup(void) {   serial.begin(9600);   lcdinitialise();   lcdclear();   drawbox();    gotoxy(7,1);   lcdstring("nokia 5110");   gotoxy(4,2);   lcdstring("scroll demo"); }  void loop(void) {     while(serial.available())   {     a=a+(char)serial.read();   }   gotoxy(4,4);   serial.println(a);   lcdstring(a);   delay(200); } 

your error message tells problem is:

error: cannot convert 'string' 'char' argument '1' 'void lcdstring(char*)'*

you have function call is:

lcdstring(a); 

where a defined @ top of code as

string a=""; 

i.e. a arduino string object , lcdstring method expects char* , these 2 things cannot converted each other.

your problem should disappear when call

lcdstring( a.c_str() ); 

as c_str() method returns char *. see here reference or this question on stackoverflow.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -