Issue with writing LCD in my function
 tomcrawford            
            
                Posts: 1,129
tomcrawford            
            
                Posts: 1,129            
            
                    If I initialize an LCD in my main program and try to write to it in a function, I get this
                            Compile... Failed! -------- compiler messages -------- Included libraries: simpletools single.c: In function 'DispLCD': single.c:54:13: error: 'debug_lcd' undeclared (first use in this function) single.c:54:13: note: each undeclared identifier is reported only once for each function it appears in

 
                            
Comments
Are you using Blockly or Simple IDE. Can you cut & paste the "C" code into code blocks so if blockly we can see how blockly is translating into c (what's being declared & where.)
Tom M.
Edit: The lcd is getting connected; I can write to it from main().
// ------ Libraries and Definitions ------ #include "simpletools.h" // ------ Global Variables and Objects ------ int Temp; int MyMode; int Seconds; int Hours; int Minutes; int Date; int Month; int Day; int Year; // ------ Function Declarations ------ int constrain(int __cVal, int __cMin, int __cMax); void DispLCD(); void ReadDs(); // ------ Main Program ------ int main() { serial *debug_lcd = serial_open(17, 17, 0, 19200); // ERROR: LCD is not initialized! writeChar(debug_lcd, 17); pause(5); writeChar(debug_lcd, 12); pause(5); MyMode = 0; while (1) { ReadDs(); switch (MyMode) { case 0: break; } pause(1000); } } // ------ Functions ------ int constrain(int __cVal, int __cMin, int __cMax) { if (__cVal < __cMin) __cVal = __cMin; if (__cVal > __cMax) __cVal = __cMax; return __cVal; } void DispLCD() { writeChar(debug_lcd, (128 + (constrain(1, 0, 3) * 20) + constrain(0, 0, 19))); Temp = (Hours / 10); dprint(debug_lcd, "%x", Temp); Temp = (Hours % 10); dprint(debug_lcd, "%x", Temp); dprint(debug_lcd, ":"); return; } void ReadDs() { low(6); shift_out(8, 7, LSBFIRST, 8, 0xBF); Seconds = (shift_in(9, 7, LSBPRE, 8)); Minutes = (shift_in(9, 7, LSBPRE, 8)); Hours = (shift_in(9, 7, LSBPRE, 8)); Date = (shift_in(9, 7, LSBPRE, 8)); Month = (shift_in(9, 7, LSBPRE, 8)); Day = (shift_in(9, 7, LSBPRE, 8)); Year = (shift_in(9, 7, LSBPRE, 8)); high(6); return; }Tom M
I tried running debug_lcd in a new cog and initializing in the new cog. Same problem; the initializing statement shows up in main.
I tried printing to debug_lcd in main (without a separate function) and it worked.
Tom M
For example for a bluetooth device that I am going to call in a function or use in a separate cog I will: I think that Blockly needs to do the same.
Tom M
Blockly folks, I think this is a pretty serious restriction. What do I have to do to get this on the "to-fix" list?
Thanks for bringing this up. The best way to get any bug or enhancement on our radar is to post it to the Parallax GitHub issues list for that project. This one would go to:
https://github.com/parallaxinc/BlocklyProp/issues/
I went ahead and posted this one as an example:
https://github.com/parallaxinc/BlocklyProp/issues/1391
...and encourage you to join and submit if you find any more issues.
Thanks again, Andy