Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use Text Value Display
#1
Hey Guys, 

I know there has already been an answer to this issue but still it doesnt work for me.
When doing it exactly as in the example: 

https://virtuino.com/forum/showthread.ph...text+value

It just doesnt display a text. Dumbers work fine but String doesnt work at all...



String text1="Hello";  //Declare some variable for the text.  On Virtuino use the pin V32
String text2="";  // V33
String text3="";  // V34

//============================================================== onCommandReceived
//==============================================================
/* This function is called every time Virtuino app sends a request to server to change a Pin value
* The 'variableType' can be a character like V, T, O  V=Virtual pin  T=Text Pin    O=PWM Pin
* The 'variableIndex' is the pin number index of Virtuino app
* The 'valueAsText' is the value that has sent from the app  */
void onReceived(char variableType, uint8_t variableIndex, String valueAsText){   
    if (variableType=='V'){
        float value = valueAsText.toFloat();        // convert the value to float. The valueAsText have to be numerical
        if (variableIndex<V_memory_count) V[variableIndex]=value;              // copy the received value to arduino V memory array
        else if (variableIndex==32) text1=valueAsText;  // V32 -> Text
        else if (variableIndex==33) text2=valueAsText;  // V33 -> Text
        // else if (variableIndex==34) text3=valueAsText; // V34 ->Text
    }
   
    }
}

//==============================================================
/* This function is called every time Virtuino app requests to read a pin value*/
String onRequested(char variableType, uint8_t variableIndex){   
    if (variableType=='V') {
    if (variableIndex<V_memory_count) return  String(V[variableIndex]);  // return the value of the arduino V memory array
    else if (variableIndex==32) return text1;  // V32 -> Text
        else if (variableIndex==33) return text2;  // V33 -> Text
        // else if (variableIndex==34) return text3; // V34 ->Text
  }
 
  return "";
}

Should the text value display now display "Hello" if i declare it to be V[32]?
Or do I need to call it somehow to declare that V[32] should display the string text1 in the text value display any other way than virtuinoRun(); ?




Thanks for the Help!
Reply
#2
Hi,

first of all the code needs this correction here

void onReceived(char variableType, uint8_t variableIndex, String valueAsText){ 
    if (variableType=='V'){
        // float value = valueAsText.toFloat();        
        if (variableIndex<V_memory_count) {
             float value = valueAsText.toFloat();
             V[variableIndex]=value;
         }
        else if (variableIndex==32) text1=valueAsText;  // V32 -> Text
        else if (variableIndex==33) text2=valueAsText;  // V33 -> Text
        // else if (variableIndex==34) text3=valueAsText; // V34 ->Text
    }
 
    }
}


No, you don't need to do something else.
Now you have to see the message "Hello" on the "Text Value Display" in case you have selected the variable V32.
Every time the app requested for the V12 the function "onRequested" returns the "text1"

On the loop code you can change the text of this variable every time you want to change the displayed message.


    }
   
    }
}
Reply
#3
Hey, thanks for your fast reply!

Unfortuately it doesnt work...

This is my full code 

#include "VirtuinoCM.h"
VirtuinoCM virtuino;
#define V_memory_count 32 // the size of V memory. You can change it to a number <=255)
float V[V_memory_count]; // This array is synchronized with Virtuino V memory. You can change the type to int, long etc.
boolean debug = true; // set this variable to false on the finale code to decrease the request time.
String V16 = "Hello";
//============================================================== setup
//==============================================================
void setup() {
if (debug) {
Serial.begin(9600);
while (!Serial) continue;
}
String V16 = "Hello";
Serial.begin(19200);
Serial1.begin(9600);
Serial1.setTimeout(50);


virtuino.begin(onReceived,onRequested,256); //Start Virtuino. Set the buffer to 256. With this buffer Virtuino can control about 28 pins (1 command = 9bytes) The T(text) commands with 20 characters need 20+6 bytes
//virtuino.key="1234"; //This is the Virtuino password. Only requests the start with this key are accepted from the library

pinMode(4, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(13, OUTPUT); // On Virtuino panel add a button to control this pin
pinMode(6, INPUT); // On Virtuino panel add a led to get the state of this pin
pinMode(7, INPUT); // On Virtuino panel add a led to get the state of this pin
}
//============================================================== loop
//==============================================================
void loop() {
virtuinoRun();




vDelay(1000); // This is an example of the recommended delay function. Remove this if you don't need
Serial.println("V16"+V16);
}








//============================================================== onCommandReceived
//==============================================================
/* This function is called every time Virtuino app sends a request to server to change a Pin value
* The 'variableType' can be a character like V, T, O V=Virtual pin T=Text Pin O=PWM Pin
* The 'variableIndex' is the pin number index of Virtuino app
* The 'valueAsText' is the value that has sent from the app */
void onReceived(char variableType, uint8_t variableIndex, String valueAsText){
if (variableType=='V'){
if (variableIndex<V_memory_count) {
float value = valueAsText.toFloat(); // convert the value to float. The valueAsText have to be numerical
V[variableIndex]=value; // copy the received value to arduino V memory array
}
else if (variableIndex== 16 ) V16= valueAsText;

}
}
//==============================================================
/* This function is called every time Virtuino app requests to read a pin value*/
String onRequested(char variableType, uint8_t variableIndex){
if (variableType=='V') {
if (variableIndex<V_memory_count) return String(V[variableIndex]); // return the value of the arduino V memory array
else if (variableIndex==16) return V16;

}
return "";
}
//============================================================== virtuinoRun
void virtuinoRun(){
while (Serial1.available()) {
char tempChar=Serial1.read();
if (tempChar==CM_START_CHAR) { // a new command is starting...
virtuino.readBuffer=CM_START_CHAR; // copy the new command to the virtuino readBuffer
virtuino.readBuffer+=Serial1.readStringUntil(CM_END_CHAR);
virtuino.readBuffer+=CM_END_CHAR;
if (debug) Serial.println("\nCommand= "+virtuino.readBuffer);
String* response= virtuino.getResponse(); // get the text that has to be sent to Virtuino as reply. The library will check the inptuBuffer and it will create the response text
if (debug) Serial.println("Response : "+*response);
Serial1.print(*response);
break;
}
}
}

//============================================================== vDelay
void vDelay(int delayInMillis){long t=millis()+delayInMillis;while (millis()<t) virtuinoRun();}




I am using virtuino cm 1.0.2. 


Serial Monitor Output is:

13:11:13.729 -> V16Hello



13:11:13.729 ->



13:11:13.729 -> Command= !V16=?$



13:11:13.729 -> Response : !V16=0.00$



13:11:13.729 -> V16Hello



13:11:13.729 -> V16Hello


It also prints the Value of V[16] in my text value display...

Hope this clarifies it a bit
Reply
#4
Hi,
the first 32 variables are used as float number.
You have to use the Variables from V32 and above. Or to reduse the V_memory_count to 15
#define V_memory_count 15
Reply
#5
Yes Thank you very much, it worked!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)