Trouble with Switch Icon

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Trouble with Switch Icon

Post by ionize »

This is my on-going spa control project. I am trying to consolidate "0" and "2" in the Display Functions. The program defaults to "0" Display Function and pushing the UP/DN buttons switches to "2" Display Function and then back to "0" as soon as you let go. This works, the problem is it won't go to the next Display Function("1") Minutes and allow adjustment, no matter how many times I push the "Program" button and beg it to work. Can't figure out a fix. everything else is OK. Please show me the way.
Oh and the simulation doesn't quite work right but it works in the board.
Thanks,
Scott
Attachments
Spa_C.fcfx
(57.59 KiB) Downloaded 200 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Trouble with Switch Icon

Post by medelec35 »

Hi Scott
This is cause of your issue:
Decision.png
(19.78 KiB) Downloaded 2154 times
you are using all OR (||) functions.
So:

Code: Select all

If  Up is 0 OR  Down is 0 OR UP_b is 0 OR Down_b is 0 OR Count_4 > 30 then reset DisplayFunction to 0
Not sure that is what you want to do since as soon as this icon is reached,if no keys have been pressed then DisplayFunction to 0.
If you wanted a timeout of no keys being pressed after 30 seconds then you will need to change the above decision to:

Code: Select all

(Up = 0 || Down = 0 || UP_b = 0 || Down_b = 0) && Count_4 > 30
If it was me I would also add and additional decision:

Code: Select all

(Up = 1) || (Down = 1) || (UP_b = 1) || (Down_b = 1) then Count_4 = 0
What this would do is reset Count_4 to 0 each time a key is pressed.
This is because without the extra decision as soon as Count_4 = 31 then DisplayFunction will be reset to 0 even if you are still pressing the up/down keys.
So it changes to a time out of 31 seconds only from when no keys are detected.

Note: I enclose any multiple tests within in their own separate brackets.
This is because a long time ago I had a problem with a decision branching at the wrong time and the fix was to include brackets for every individual test e.g (Up = 1) || (Down = 1) || (UP_b = 1) etc.
That may not be the case now, but I still do that out of habit.

The other thing I have noticed is you are calling macro from within the interrupt.
That is bad practice and can cause all sorts of issues.
You must allow the interrupt to exit normally without any calls to macros.

Hope this helps?

Martin
Martin

User avatar
ionize
Posts: 25
Joined: Fri Aug 05, 2011 8:01 pm
Has thanked: 29 times
Been thanked: 11 times
Contact:

Re: Trouble with Switch Icon

Post by ionize »

Of course, you are right :D Thank you very much. After applying your code and advice, which fixed everything, I decided to try and have a slow then fast number change on "display function 1". I only tried on the RED buttons and they now count by two but not appreciably faster than the BLUE buttons nor can I tell why they count by two and the numbers selected, RED and BLUE, don't store in eeprom anymore. Is it possible to do? Any pointers?
Also, I don't know how to write "THEN Count_4 = 0" so V6 likes it. I looked around for a list of common functions (or is it arguments) like and, nand, or, nor, etc., but I couldn't find one yet.
Thanks,
Scott
Attachments
Spa_C_1.fcfx
(66.56 KiB) Downloaded 217 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Trouble with Switch Icon

Post by medelec35 »

Hi Scott,
ionize wrote:RED and BLUE, don't store in eeprom anymore. Is it possible to do? Any pointers?
I will take a look at your flowchart an see if I can spot the issue.
ionize wrote: don't know how to write "THEN Count_4 = 0
I just tried writing in pseudocode, sorry if confusing.
Then is just the Yes branch which is the same as true.
so all you do is:
Time out1.png
(6.74 KiB) Downloaded 2124 times
Perhaps a better more efficient way would be:
Time out2.png
(6.95 KiB) Downloaded 2124 times
ionize wrote:I decided to try and have a slow then fast number change on "display function 1".
If it was me I would use a long/short press detection.
Take a look here

Martin
Martin

Post Reply