Announcement

Collapse
No announcement yet.

Arduino uno and the uLCD-35DT

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    just did a reset on the arduino and it is now running at the correct speed.... seems I need to do that after each download.... sorry to bother you....

    Comment


    • #17
      Code:
      #include <genieArduino.h>
      
      Genie genie;
      
      bool isRunning = 1;
      int Cycle_minutes = 1;
      int seconds = 0; // track count down seconds
      int minutes; // tracks count down minutes
      long int numberOfRotations = 0; // tracks number of completed Rotations
      uint32_t cycle_delay;
      
      void setup() {
        Serial.begin(115200);
        genie.Begin(Serial);
      
        genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events
        if ( genie.online() ) genie.WriteContrast(15); // 1 = Display ON, 0 = Display OFF
      
        numberOfRotations++;
        minutes = Cycle_minutes;
        turningTheCrank();
        myRotations();
      
      }
      
      void loop() {
        genie.DoEvents();
      
        if ( millis() - cycle_delay > 1000 && isRunning ) {
          cycle_delay = millis();
          seconds = seconds - 1;
          if (seconds <= 0) {
            minutes = minutes - 1;
            if (minutes == -1) {
              turningTheCrank();
              numberOfRotations++;
              myRotations();
              minutes = Cycle_minutes - 1;
              seconds = 60;
            }
            else {
              seconds = 60;
            }
          }
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, minutes);
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 1, seconds );
        }
      
      
      }
      
      
      
      void myRotations() {
        String junk = "rotations = " + String(numberOfRotations);
        genie.WriteStr(0, junk);
      }
      
      void turningTheCrank() {
        String junk = ("Turning the Crank");
        genie.WriteStr(0, junk);
        delay (3000);
        junk = "                 ";
        genie.WriteStr(0, junk);
      }
      
      
      void myGenieEventHandler() {
        genieFrame Event;
        genie.DequeueEvent(&Event);
        if (Event.reportObject.cmd == GENIE_REPORT_EVENT && Event.reportObject.object == GENIE_OBJ_4DBUTTON ) {
          if (Event.reportObject.index == 0) { // if button 0, do something
            String junk2 = ("Pressed RUN");
            genie.WriteStr(0, junk2);
            delay(2000);
            isRunning = true; // release the timer to continue where it left off
            junk2 = "rotations = " + String(numberOfRotations);
            genie.WriteStr(0, junk2);
      
          }
          if (Event.reportObject.index == 1) { // if button 1, do something
            isRunning = !isRunning;
            String junk2;
            ( isRunning ) ? junk2 = "rotations = " + String(numberOfRotations) : junk2 = ("PAUSED");
            genie.WriteStr(0, junk2);
          }
      
        }
      }
      How about this? changed your bool to more logical sense and defaulted it to 1 on startup, added ternary operator in button1 event

      Tony
      Last edited by tonton81; 11th August 2017, 04:19 AM.

      Comment


      • #18
        OK< me again.... leveraging from the code that tonton81 provided me, thanks Man!, I proceeded to creat a second form and placeed a gfew buttons and digital LEDs... I thought I have it but when I press the buttons to increase or decrease a value, I get no update to the leds ...

        Click image for larger version

Name:	form0 screen.png
Views:	1
Size:	47.9 KB
ID:	59242Click image for larger version

Name:	form1 screen.png
Views:	1
Size:	48.5 KB
ID:	59243

        minutes and seconds update just fine. When the pause button is pressed, it is linked to form1, there I want to tage the up down buttons to increment the leds

        here's the code section .... any thoughts!

        void myGenieEventHandler() {

        genieFrame Event;
        genie.DequeueEvent(&Event);

        if (Event.reportObject.cmd == GENIE_REPORT_EVENT && Event.reportObject.object == GENIE_OBJ_4DBUTTON ) {

        if (Event.reportObject.index == 0) { // if button 0, do something
        String junk2 = ("Pressed RUN");
        genie.WriteStr(0, junk2);
        // delay(2000);
        isRunning = true; // release the timer to continue where it left off
        junk2 = "rotations = " + String(numberOfRotations);
        genie.WriteStr(0, junk2);
        }

        if (Event.reportObject.index == 1) { // if button 1, do something
        isRunning = false;//!isRunning;
        genie.WriteObject (GENIE_OBJ_FORM, 1,0);

        }

        // rotation Angle settings area *******************

        if (Event.reportObject.index == 3) { // if button 3, rotation angle Increased
        rotationAngle = rotationAngle + 1;
        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, rotationAngle);
        }

        if (Event.reportObject.index == 4) { // if button 3, rotation angle decreased
        rotationAngle = rotationAngle - 1;
        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 2, rotationAngle);
        }

        // rotation Cycles in minutes area ***************

        if (Event.reportObject.index == 5) { // if button 4, rotation rotation Increased
        rotationMinutes++;
        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, rotationMinutes);
        }

        if (Event.reportObject.index == 5) { // if button 5, rotation minutes decreased
        rotationMinutes--;
        genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, rotationMinutes);
        }

        // Update settings *******************

        if (Event.reportObject.index == 7) { // if button 7, update minutes and angle
        minutes = rotationMinutes;
        rotationalAngle = rotationAngle;
        }
        }
        }

        Comment


        • #19
          please repost your zip project with the new form added as you only posted the arduino code

          i also see an error here:

          Code:
          if (Event.reportObject.index *== 5*) { // if button 4, rotation rotation Increased  <--------------------
          rotationMinutes++;
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, rotationMinutes);
          }
          
          if (Event.reportObject.index *== 5*) { // if button 5, rotation minutes decreased     <--------------------------
          rotationMinutes--;
          genie.WriteObject(GENIE_OBJ_LED_DIGITS, 3, rotationMinutes);
          }
          this could explain why your getting no movement, one button is not captured, and the other button is triggered twice because of duplicate sub function, which both adds updates then subtracts and updates, you wouldnt see it happen as its very quick, and would presume it wouldn't be working at this point

          Tony
          Last edited by tonton81; 12th August 2017, 10:35 AM.

          Comment

          Working...
          X