Hello. I have the following scenario that I need to develop:
I have a gate and a barrier in a lock. I want to create an interlocking system in which, by pressing a button, the gate open, and when closing the barrier it open automatically, only allowing the gate to be opened again after the barrier is closed. Here's the big problem. I want that, if, in the middle of the process, the opening button is pressed again, the controller waits for the cycle to end to automatically trigger the opening of the gate again, starting the cycle again. Example: car A presses the button, the gate opens and it enters the lock. Before the gate closes completely, car B presses the button again. Controller waits for the gate to close, open the barrier after closing and as soon as it finds that the barrier has closed, it automatically open the gate and restarts the cycle.
Can someone help me?
Start by deciding on the hardware.
You need to specify the gate and how it will be powered and controlled, specify the lock and how it will be controlled, pick a processor (e.g. Arduino), then figure out how the processor will be powered on site and how it will interact with the gate and lock hardware.
The program comes later.
Word salad.
Draw a timing diagram or a state transition chart or flow chart or any kind of visual representation of how this is supposed to work.
Google for examples, select images…
timing diagram
state transition diagram
flowchart
I’ve tried making any sense of your prose and cannot. It seems ambiguous or contradictory and gave me a heads ache.
a7
consider
const byte ButPin = A1;
const byte ActivityPin = 12;
const byte ClosedPin = 13;
byte butState;
bool cycle;
bool cyclePend;
enum { Off = HIGH, On = LOW };
// -----------------------------------------------------------------------------
enum { DirOpen = 1, DirClose = -1 };
const int PositionMax = 10;
const unsigned ActivityPeriod = 200;
void
open ()
{
static int position;
static int direction;
static unsigned long msecLst;
unsigned long msec = millis ();
if ( (msec - msecLst) < ActivityPeriod)
return;
msecLst = msec;
Serial.println (__func__);
digitalWrite (ActivityPin, ! digitalRead (ActivityPin));
if (0 == position)
direction = DirOpen;
else if (PositionMax <= position) {
direction = DirClose;
digitalWrite (ClosedPin, Off);
}
position += direction;
if (0 == position) {
cycle = false;
digitalWrite (ClosedPin, On);
}
}
// -----------------------------------------------------------------------------
void
loop ()
{
static byte butState = Off;
byte but = digitalRead (ButPin);
if (butState != but) {
butState = but;
delay (10); // debounce
if (On == but) {
if (cycle)
cyclePend = true;
else
cycle = true;
}
}
if (cycle)
open ();
else if (cyclePend) {
cyclePend = false;
cycle = true;
}
}
// -----------------------------------------------------------------------------
void
setup ()
{
Serial.begin (9600);
pinMode (ButPin, INPUT_PULLUP);
butState = digitalRead (ButPin);
digitalWrite (ActivityPin, Off);
pinMode (ActivityPin, OUTPUT);
digitalWrite (ClosedPin, On);
pinMode (ClosedPin, OUTPUT);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.