Yes, this is absolutely correct. Thank you! I was trying to figure out the way of doing it without the delay() but with millis().
I like the idea of sending 200ms pulse, it creates possibility to do it without the delay().
I figured every detail is very important for the logic so I quickly created the design and screen grabbed it to make gif from animation. This is how the system should work.
Notes about this animation: Top two rows represent blast gates, in the middle is the dust collector and bottom two rows - equipment.
Top rows colors:
green = blast gate open (air piston extended) activated by opening relay for 200ms.
red = blast gate closed (air piston retracted) activated by closing relay for 200ms. Middle row:
Dust Collector ON or OFF powered by the Arduino relay that drives large 3 phase contactor. Dust Collector is ON when any of the equipment is on. When last equipment is tuned off dust collector will run for additional 40 seconds with all blast gates open, if equipment turned on and turned off within 10 seconds Dust Collector will run regardless for 40 seconds(to protect motor). This logic I have figured out with the use of millis(). I was not able to show the delay in animation, it would have been long animation. Button press/unpress immediate reaction to blast gate and dust collector has a delay turn off timer. This is why I wanted to have all blast gates open by default for safety reasons. Never all closed. Bottom row:
Equipment colored gray means turned off (button not pressed), pale red means turned on (button pressed in). However to clarify, Table saw will have contractor(relay) instead of latching button(same principal, it just have one built in that engages once turned, it has options NO or NC. Shaper, drill press, planer will have Current Transformers attached to measure current draw and I could code certain values range to read as true or false for integration with buttons logic. And the rest of the equipment will have latching buttons.
I should have done the animation sooner.
I unfortunately was not able to play with the code. ADS1115 shorted out on me and I spend past days trying to figure out what is wrong disassembling piece by piece and troubleshooting everything. However replacement will arrive Friday.
With the zero you suggest something like a passFlag, once run it should reset for a future use and if so it will cycle the gate. Open Close with 200ms intervals. If passFlag is changed once run, then same button will not work until Arduino restart.
if( passFlag == 0 ) // in this case it will run only one
{
digitalWrite(pin);
passFlag++;
}
Thank you @paulpaulson .
I was not able to play with the code yet, due to the technical difficulties , but I expect replacement part to arrive this Friday.
I also posted an animation of how the design should work in my previous post. It helps to understand the whole design. It also has another equipment that behaves with different logic. I realize I should have done it earlier.
With this sentence you seem to understand how it works
With this sentence you seem to not understand how it works
the variable is set to zero indicate "don't create a pulse"
whenever the value is unequal to zero this indicates: "check if 200 millisecond have passed by" and if 200 millisecond have really passed by terminate 200 millisecond pulse through switching IO-pin.
I'm sorry to say I don't understand your animation. Not even with the additional text. There is going on so many things in parallel that I don't grasp it. We (all the other users have never worked in your shop = zero experience with it.
This animation is a case where you are the one that has "blindness of the expert about beginner difficulties"
The professional way to explain such things is to use time-charts or trueth-tables (state-tables). With an unanimated = standing still time-chart everybody can evaluate how things are timely related.
There is still some use in the animation and the text as it gives an overview about your project.
You mentioned that an ADC ADS1115 was damaged and that you narowed down the fault.
For building up the software I highly recommend that you add only one thing at a time and do a lot of pre-tests with small testcodes for things like current detecting etc.
Can you really confirm if you are pulse driven (LOW - HIGH - LOW will flip the state) or front/level driven (LOW to HIGH or HIGH to LOW) driven ?
If you are pulse driven and want to manage that without delay then you need a mini state machine per output with (for example) cureentState (idle, energized, in pulse) and a timer (startPulseTime). You put all these in a struct and the loop constantly checks the buttons for action and triggers the state change in the struct and then you also have a loop that checks all the structs and if the state is in pulse mode then do the right thing to terminate the pulse after the 200ms and inverse the state record.
This is an insanely long and complex thread, and a large part of the reason for that is the fact that it's explained in too many words, not enough charts, tables, diagrams.
edit- and I suspect a large part of the hassle with the coding is the premature hitting of the coding keyboard with exactly that lack of charts, tables and diagrams.
I ended up placing all of the relays in the same box as the arduino and solenoids just a feet away. However I did run 24v DC and 120VAC signal wires approximately 40' each. This time I have the schematic diagram. LINK to GitHub
I took advantage of the opto isolators and used separate PSU for the solenoids, not connected to the main negative with flyback diodes (Schottky diode). However I did not show Schottky diodes on the diagram.
GitHub has schematic diagram and the code.
I settled with if-else for the logic. For some reason I was not able to make switch function to work properly with millis(). It would activate the dust collection and open-close proper gate but would not display time running.
Would love to hear suggestions on the code, a better alternative to if-else for instance of having more than 3 inputs.
Participants tend to read right here and not click on links so unless it’s many long files usually it’s best to post the code here.
Also it helps freeze what we discuss about and keep track of changes. Someone joining the thread in a few days would not know easily if you modified the GitHub repository in between (depending on how you manage and document commits) and it makes informatjon gathering complicated.
So long story short either you have a list of participants and you keep everything in GitHub with their system for bugs and changes or you post here would be my advice
hm you organised your code into tabs (= multiple files).
Well then you should point to that files that the user here shall look at.
And as recommended earlier
add a detailed description how your code behaves and what you would like to have different
-add a timing-chart that shows that case that is not functioning as you want
The probaility to get profund help will be higher if you guide your potential helpers to get an oversight about your code