Announcement

Collapse
No announcement yet.

Change form on external input

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

  • Change form on external input

    Im trying to use the Arduino digital input to change to form1 when the input is active and change back to form0 when the input is low. In my project I am planning I need it to be able to switch to up to 10 different forms quite rapidly on inputs. Im fairly new to coding and I dont mind taking it slow but been stuck on these forms for two weekends now and not getting anywhere.

    At first I tried:
    Code:
    if(digitalRead(16) == 1) { 
        genie.WriteObject(GENIE_OBJ_FORM, 1,0);
      }
    It works but the form flickers, so I figured it may be because it keep repeating the form1 command and "refreshes" it?

    Then I tried this but I cant get the hang of it. my variable "form" is not updated so it just ends up flickering on form0. It is based on the code for genieArduino example. I have also tried to use the switch case like in genieFormBasic example and then just write form = 1; for case 1 etc but its the same problem. I must be missing something fundamental. Any advice is very appreciated.

    The input is a switch on input 16 with a 10k resistor to ground.



    Code:
    #include <genieArduino.h>
    int form;
    Genie genie;
    #define RESETLINE 4  
    void setup()
    {
     
      Serial.begin(200000); 
      genie.Begin(Serial);  
    
      genie.AttachEventHandler(myGenieEventHandler); 
     
      pinMode(RESETLINE, OUTPUT);  
      digitalWrite(RESETLINE, 1);  
      delay(100);
      digitalWrite(RESETLINE, 0);  
    
      delay (3500); 
    
     
      void loop()
    { 
      genie.DoEvents();
      
      if(digitalRead(16) == 1 && form == 0){ 
        genie.WriteObject(GENIE_OBJ_FORM, 1,0);
      }
      if(digitalRead(16) == 0 && form = 1){ 
        genie.WriteObject(GENIE_OBJ_FORM,0,0);
      }
      
    
    }
    
    
    void myGenieEventHandler()
    { 
      genieFrame Event;
      genie.DequeueEvent(&Event);
    
      if(Event.reportObject.cmd == GENIE_REPORT_EVENT)
      {
        if (Event.reportObject.object == GENIE_OBJ_FORM)     
        {
          if (Event.reportObject.index == 0)         
          {
            form = 0;
          }
          else if (Event.reportObject.index == 1)     
          {
            form = 1;
          }
        }
      }
      
    }

  • #2
    I can't see if you fave form change messages coming back to the arduino, bit really it doesn't matter. In the time it takes for the form change messsage to go out, be processed and come back you could have 'reented' the change code thousands of times.

    So something like this would be a better start

    Code:
      if(digitalRead(16) == 1 && form == 0){ 
        genie.WriteObject(GENIE_OBJ_FORM, 1,0);
        form = 1 ;
      }
    Mark

    Comment


    • #3
      Ahh yes, That worked perfectly. I was too hung up on the event report and kept editing that.

      Thanks, saved my weekend!

      Comment

      Working...
      X