I would like to execute a function by sending a case using Labview. The idea is to control a 2.8" TFT LCD (http://www.nuelectronics.com/estore/index.php?main_page=product_info&cPath=1&products_id=19) and to display defined patterns upon calling a case via Labview. To this end I have modified the LIFA (Labview Interface for Arduino) provided by National Instruments and applied it sucessfully, e.g. to make an led blink (=calling functions by sending a case via Labview works). I also sucessfully used the Arduino TFT library (www.nuelectronics.com/download/projects/TFT_lib.zip) to control the LCD. What I can't get to work is the combination of the TFT library and LIFA. All connections are functional, Labview works, the arduino works, the library works and calling self-made functions works, the compiler is not complaining. Would you please have a look at my code and check what I am doing wrong here? Thank you very much!
Please excuse the inappropriate terminology, I am very new to C++ and Arduino. And thank you for correcting me - that's the best way for learning new languages (at least from my own experience).
My code is supposed to initialize a TFT LCD and set the pixel color to red. When I use a simple sketch as shown below the LCD is initialized and the pixel color is set to red:
When I use the above shown code with the Labview Interface for Arduino, i.e. send data via Labview to Arduino, that evaluates it in a switch statement and executes a case block, the TFT LCD is not initialized and red pixels are not turned on.
This is the data send by Labview: 0x41
This is my case block:
case 0x41: // Data sent by Labview
MyTFT(); // Function called in the case block
break;
This is the function MyTFT () called in the case block:
void MyTFT()
{
Graphics tft; //Create object of class 'Graphics' in library header file Graphics.h
tft.initialize(LCD_HORIZONTAL); //LCD initialization
tft.ClearScreen(RED); //turn on red pixels
}
Please find the complete Labview Interface for Arduino sketch attached to the first posting.Hope this is a bit clearer. Thanks again!
When I use the above shown code with the Labview Interface for Arduino, i.e. send data via Labview to Arduino, that evaluates it in a switch statement and executes a case block, the TFT LCD is not initialized and red pixels are not turned on.
How do you know that MyTFT() is even being called?
In that method, you create a local variable, tft, and call two methods on that instance. Then, the function ends and the local instance goes away. This may well undo any changes that the instance made to the hardware.
I am mot entirely sure that MyTFT() is called, but what I did is that I used a MyBlink() function (turns on and off and led) in the same case block after MyTFT(). My Blink() was executed and the led blinked upon sending data via labview.
I also used tft as global variable (listed just after the include statements) but I got the same result as in the example provided. I will try it with tft as a global variable again.
So if MyTFT is called but you don't observe what you expect, then it probably means MyTFT function doesn't work. I'd write a test sketch that would leave all the labview stuff out and just test MyTFT.
Bertbert:
Ok, but how do I 'simulate' the data send by Labview to execute the case block?
Just send the byte labview would send, only don't use labview but a serial terminal. Ascii code 0x41 is 65, i.e. 'A' (capital A) char. You can even use arduino serial monitor...
I followed your suggestions and found that MyTFT() was not executed but I figured out a way that involved ending and re-starting the serial communication to get the custom code running. Thanks heaps for your comments!