@adigitaldj1
I am a scorpio and were naturally introverted
Well, I have that in common... Thank to let me know what state/Province. I hear Ohio State trouper are a "bit picky"...
About you problem in coding... C++ is a different ball game than BASIC.
I re-read this tread, It look like you want : press button, flash the light in the sequence you want, no press, no light flashing .... I am correct ? OK let assume that... Programing the Arduino, you have to know what you want to do.
Here is a concept code :
void setup()
{
// your pin setup
}
void loop()
{
read the switch
if swich is on = state = on
while(state)
{
flash the light
re-check the switch
if switch is on = state on
if no on, state = off
}
I did a code simila to that. It my school bus light system. Just re-modify this code to fit your need.
Here the code :
/*
size : 1692 bytes
Version 2.1
file name : schoolbussignal.pde
School Bus Alternating Light Simulator
It simulate the activation system to activate the alternating
red light, stop sign and crossing gate of the school bus.
Here the parts you need :
4 - 330 ohms limiting resistors for the LED's
2 - Red LED
2 - Green KED
3 - 10 K resistor pull-down resistor
2 - SPDT or SPST switch or DIP switch
1 - Push-on button switch
How it work :
1. To activate the system, turn on MASTER switch.
2. Press the push button to activate the Red Lights ONLY.
3. When the door is open, a swtich is close ( the door switch is ON )
and activate the stop sign ( left side of the bus )
and crossing ( front of the bus ) gate.
4. Close the door ( turn the door off ) to turn off everythings.
5. When open the door ( turn on/off door switch ) and
Master switch is OFF, nothing will happen.
6. Even you press the push button and the Master switch is OFF,
nothing will happen.
Program by Serge J Desjardins aka techone
Re-Modify with the help of AWOL
Compile and Tested
*/
// input pin
const byte masterpin=12;
const byte doorpin=11;
const byte pushbuttonpin=10;
/*
pin 12 : Master Switch
pin 11 : Door Switch
pin 10 : Push button to activate
*/
// output pin
const byte busoutpin[4]={9,8,7,6};
/*
pin 7 : Alterning Light A
pin 6 : Alterning Light B
pin 5 : Front gard gate motor on/off
pin 4 : Stop sign motor on/off
*/
byte master=0; // Master Switch
byte door=0; // Door Switch
byte pushbutton=0; // Push Button
boolean buttonstate; // State Control
boolean doorstate;
void setup()
{ // init out & in pin
pinMode(masterpin, INPUT);
pinMode(doorpin, INPUT);
pinMode(pushbutton, INPUT);
for (int i=0;i<4;i++)
{
pinMode(busoutpin[i], OUTPUT);
}
// turn the output pins off
for (int i=0;i<4;i++)
{
digitalWrite(busoutpin[i], LOW);
}
buttonstate=0;
doorstate=0;
turnoff();
}
void loop()
{
// check for the push button ON or door switch ON
while ((buttonstate==0) && (doorstate==0))
{
// check the master switch again
master=digitalRead(masterpin);
delay (100);
// check push button again
pushbutton=digitalRead(pushbuttonpin);
delay (100);
if ((pushbutton==1) && (master==1))
{
buttonstate=1;
}
// check the door switch again
door=digitalRead(doorpin);
delay (100);
if ((door==1) && (master==1))
{
doorstate=1;
buttonstate=1;
}
// when door is open and master switch is off
if ((door==1) && (master==0))
{
doorstate=0;
buttonstate=0;
}
}
// stay in loop when the master id ON AND the push button is press
while ((master==1) && (buttonstate==1))
{
// check the master switch again
master=digitalRead(masterpin);
delay (100);
if ((master==1) && (buttonstate==1))
{
// push button is press AND master is ON
alternating();
}
// check the door again
door=digitalRead(doorpin);
delay(100);
// the door is open with master on
if ((door==1) && (master==1))
{
doorstate=1;
alternating();
motorson();
alternating();
}
// after the door was open and closing the door
if ((door==0) && (doorstate==1))
{
buttonstate=0;
}
}
// turn off everythings when master is off or door is close
if ((master==0) || (door==0))
{
doorstate=0;
buttonstate=0;
motorsoff();
turnoff();
}
}
// alternating red light routine
void alternating()
{
digitalWrite(busoutpin[0], HIGH);
digitalWrite(busoutpin[1], LOW);
delay(500);
digitalWrite(busoutpin[0], LOW);
digitalWrite(busoutpin[1], HIGH);
delay (500);
}
// turn off everythings routine
void turnoff()
{
for (int i=0; i<4;i++)
{
digitalWrite(busoutpin[i], LOW);
}
}
//deploy stop sign motor and crossing gate motor
void motorson()
{
digitalWrite(busoutpin[2], HIGH);
digitalWrite(busoutpin[3], HIGH);
}
//re-track back stop sign and crossing gate
void motorsoff()
{
digitalWrite(busoutpin[2], LOW);
digitalWrite(busoutpin[4], LOW);
}