Announcement

Collapse
No announcement yet.

Changing to another form using an external interrupt

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

  • Changing to another form using an external interrupt

    Attached you will see my code. I am attempting to action the "flameUpdate" function upon servicing the external interrupt on pin 3. I know that the interrupt is actioning correctly since an LED is turning on while the interrupt occurs. However, the display only sometimes changes. I feel that when i reset everything it sometimes works. It may be a clock synchronisation issue? EDIT: I am using the gen4 28p4 display.
    Please help.
    #include <genieArduino.h>
    #include <stdio.h>

    #define RESETLINE 4
    #define fanOnePin 7
    #define fanTwoPin 5

    Genie genie;

    int monitorButton;
    int lightsButton;
    int caseTemp;
    int fanOneState;
    int fanTwoState;
    int fanSpeed;

    int tempPin = A0;
    int flamePin = 3;

    void setup()
    {
    interrupts();
    // Set the baud rate for the genie software
    Serial.begin(9600);
    genie.Begin(Serial);
    // Lights Status
    // pinMode(2, OUTPUT);
    // Monitor Status
    pinMode(4, OUTPUT);
    // Fan 1 Speed
    pinMode(fanOnePin, INPUT);
    // Fan 2 Speed
    // pinMode(fanTwoPin, INPUT);
    // Reset the display upon startup
    pinMode(RESETLINE, OUTPUT);
    digitalWrite(RESETLINE, 0);
    delay(100);
    digitalWrite(RESETLINE, 1);
    // Adjust delay as sync issues are noticed. i.e if the display is not responding correctly
    delay(5000);
    // Flame sensor interrupt on pin 3
    attachInterrupt(digitalPinToInterrupt(flamePin), flameISR , RISING);

    //TESTING CODE MUST REMOVE
    // REMOVE THIS
    pinMode(6, OUTPUT);
    }

    void loop()
    {
    TempUpdate();
    FanUpdate(fanOnePin, 0);
    FanUpdate(fanTwoPin, 1);
    }

    void TempUpdate()
    {
    // Update Temperature value
    caseTemp = analogRead(tempPin);
    genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, caseTemp);
    }

    void FanUpdate(int whichFan, int LED)
    {
    if (digitalRead(whichFan) == HIGH)
    {
    genie.WriteObject(GENIE_OBJ_LED, LED, HIGH);
    // genie.WriteObject(GENIE_OBJ_FORM, 6, 1);
    }
    else
    {
    genie.WriteObject(GENIE_OBJ_LED, LED, LOW);
    }
    }

    void flameISR()
    {
    digitalWrite(6, HIGH);
    flameUpdate();
    }

    void flameUpdate()
    {

    while(0)
    {
    genie.WriteObject(GENIE_OBJ_FORM, 6,0);
    }

    }

  • #2
    Not sure of what you are trying to do with this loop
    Code:
    while(0)
    . It seems to me that you could end up in an endless loop. Also depending when the function is fired the condition may be true and never loop. Does an interrupt cause a break in an endless loop?
    Lastly I would avoid using names like LED for a variable. LED may be a reserved word.
    Last edited by Frank B; 1 week ago.

    Comment


    • techman
      techman commented
      Editing a comment
      Hi Frank,
      Thanks for the response.
      I have actioned an infinite loop on purpose, to ensure that the mcu remains in the interrupt until a power cycle has been experienced.
      However, I have also tried without the while loop - to no success. I can confirm that it does enter the interrupt as an LED is turning on as expected within the interrupt. However the form change does not action within the ISR. Calling the form change outside of the interrupt works without an issue.
Working...
X