No announcement yet.

testing with Arduino

  • Filter
  • Time
  • Show
Clear All
new posts

  • testing with Arduino

    Like hand phones, if the screen is not touched for a set period of time, I want the LCD screen to dim and set back to form 0. With 4Dbutton 0, the screen can be brought back to normal brightness. I am using the Arduino Mega 2560 and uLCD-43PT-AR. And also, I found that in most programs connecting Arduino and VisiGenie environment, delay function is used. However, I need to use timer in my Arduino sketch so delay function cannot be used. I'd also like to know how to write to Scope and Spectrum of 4D system from Arduino. Please suggest. Program_for_4D_workshop.doc

    Attached files Program_for_4D_workshop.doc (57.5 KB) (60.1 KB)

  • #2

    You will need to dim the display sending the contrast command from Arduino.

    There are no specific Arduino app notes for Scope and Spectrum as yet, but they are both pretty easy to use. Maybe have a look at the Diablo app notes D4003 and D4004. They are just as applicable to Picaso, and whilst they demonstrate using GTX the knowledge learned is applicable to Arduino.

    Perhaps use millis() to avoid using delay?


    • #3

      Thanks for your help.
      But my problem is how to know the screen is not being touched.


      • #4

        Well, presumably you would be sending all touches / changes / messages back to the Arduino, so if there had been no message for a while you could dim the screen and then brighten it again when a message occurred. If you turn the screen off completely change the form to one that is entirely a button so that the message will occur wherever the user touches.


        • #5

          Currently, I write the program in 4D workshop such that pressing any button will report message to the host (arduino). If there is no touch, the screen is dimmed as wanted and pressing any button would bring the screen back to normal brightness. The problem starts after that. After bringing back to normal brightness by any button for one time, the screen never goes back to dim again.


          • #6

            So is this dimming done on the Arduino, or the display?

            Surely there must be a bug in it wherever it is. (not resetting a flag, maybe?)

            You can post it here if you can't figure it out.


            • #7

              Dimming code is written in arduino side.
              void myGenieEventHandler(void) { genieFrame reply; genieDequeueEvent(&reply); int keyboardValue; if (reply.reportObject.object == GENIE_OBJ_KEYBOARD) // If this event is from a Keyboard { no_touch = 0; if (reply.reportObject.index == 0)// If from Keyboard0 { keyboardValue = genieGetEventData(&reply); // Get data from Keyboard0 keyboardKey (keyboardValue); // pass data to the keyboardKey function for processing } } if (reply.reportObject.object == GENIE_OBJ_TRACKBAR) // If this event is from a trackbar { no_touch = 0; if (reply.reportObject.index == 0)// If from track bar 0 ahr = genieGetEventData(&reply); // Get data from track bar 0 if (reply.reportObject.index == 1)// If from track bar 1 amin = genieGetEventData(&reply); // Get data from track bar 1 alert_time = (ahr*60) + amin; //change total alarm timing to minutes if (reply.reportObject.index == 2)// If from track bar 2 sv_temp = genieGetEventData(&reply); // Get data from track bar 2 } if (reply.reportObject.object == GENIE_OBJ_WINBUTTON) // If this event is from a win button { no_touch = 0; if (reply.reportObject.index == 1)// If from win button 1 genieWriteObject(GENIE_OBJ_FORM, 3, 0); // Go to form 3 if (reply.reportObject.index == 2)// If from win button 2 genieWriteObject(GENIE_OBJ_FORM, 5, 0); // Go to form 5 if (reply.reportObject.index == 3)// If from win button 3 genieWriteObject(GENIE_OBJ_FORM, 2, 0); // Go to form 2 if (reply.reportObject.index == 4)// If from win button 4 genieWriteObject(GENIE_OBJ_FORM, 1, 0); // Go to form 1 if (reply.reportObject.index == 5)// If from win button 5 genieWriteObject(GENIE_OBJ_FORM, 1, 0); // Go to form 1 if (reply.reportObject.index == 7)// If from win button 7 genieWriteObject(GENIE_OBJ_FORM, 5, 0); // Go to form 5 if (reply.reportObject.index == 8)// If from win button 8 genieWriteObject(GENIE_OBJ_FORM, 4, 0); // Go to form 4 if (reply.reportObject.index == 9)// If from win button 9 genieWriteObject(GENIE_OBJ_FORM, 3, 0); // Go to form 3 if (reply.reportObject.index == 10)// If from win button 10 genieWriteObject(GENIE_OBJ_FORM, 1, 0); // Go to form 1 if (reply.reportObject.index == 11)// If from win button 11 genieWriteObject(GENIE_OBJ_FORM, 3, 0); // Go to form 3 if (reply.reportObject.index == 13)// If from win button 13 genieWriteObject(GENIE_OBJ_FORM, 6, 0); // Go to form 6 if (reply.reportObject.index == 14)// If from win button 14 genieWriteObject(GENIE_OBJ_FORM, 5, 0); // Go to form 5 if (reply.reportObject.index == 15)// If from win button 15 genieWriteObject(GENIE_OBJ_FORM, 7, 0); // Go to form 7 if (reply.reportObject.index == 16)// If from win button 16 genieWriteObject(GENIE_OBJ_FORM, 3, 0); // Go to form 3 } else no_touch = 1;}

              And in the main;
              void loop(){ genieDoEvents(); // Screen Dimming if(no_touch==1) // If there is no touch { seconds; // Start the timer if(seconds == 10) // After 10 sec genieWriteContrast(3); // Dim the display } else { seconds = 0; // Reset the timer genieWriteContrast(15); // Bring to normal brightness }


              • #8

                1. You set no_touch to 1 if the winbutton hasn't been pressed, i.e. you ignore keyboard and trackbar touches

                2. Not sure what 'seconds;' does, if anything, did you mean 'seconds();'?

                3. You ALWAYS set contrast in your loop, you need to add code to only set it if the conditions have changed.

                Sorry, that's all I can spot


                • #9

                  void setup(){ //Initial Touch screen LCD setup
                  // Using Serail 0 with baudrate 9600 to communicate with Touch Screen LCD genieBegin(GENIE_SERIAL,9600);

                  // Communicating with Touch screen LCD genieAttachEventHandler(myGenieEventHandler);

                  genieWriteObject (GENIE_OBJ_FORM, 0, 0); // Start with form 0
                  genieWriteStr(0, " "); // Clear the passcode display genieWriteStr(1, "No Patient Lying on bed");
                  // Update person's position to Display
                  // Update 2 hr alarm to Display genieWriteObject (GENIE_OBJ_LED_DIGITS, 0, ahr); genieWriteObject (GENIE_OBJ_LED_DIGITS, 1, amin); // Update initial valve temperature to Display
                  genieWriteObject (GENIE_OBJ_LED_DIGITS, 20, sv_temp);

                  For the above program, the part in bold doesn't seem to work unless I press the Arduino reset button automatically. Is there any way to reset the program by itself?

                  Another problem is ..for writing to a predefined string in LCD, the string keeps flashing as the command for writing to the string is in the void loop(). So I rewrite the program as only if the state changes, then update the string. However, it works only for the screen in which the string is in. If I change to another screen and go back to the screen with that string, the string disappears(becomes blank), only if the state changes again, the string reappears. Is there anyway to solve the problem?
                  void loop()
                  if(pre_state!=current_state) // when the state changes
                  void updatePosition(int state)
                  case 0:
                  genieWriteStr(1, "No Patient Lying on bed"); break;
                  case 1: genieWriteStr(1, "Patient Lying on Left"); break;
                  case 2: ...