// AllenDirectionality_3PIR_2LEDS_WTwoBlinkers_230705.ino
// Four LEDs, 2 operated by PIRs and two as indicator blinkers
// tested normal yymmdd
// Layout truth table:
// Staircase_PCB_Uno_Layout_w_direct_2_LEDS_230705.jpg
// constants won't change. Used here to set a pin number :
const int ledPin9 = 9; // the number of the LED pin
const int ledPin10 = 10; // the number of the LED pin
// Variables will change :
int ledState9 = LOW;
int ledStateOff9 = LOW;
int ledState10 = LOW;
int ledStateOff10 = LOW;
unsigned long previousMillisOn9 = 0;
unsigned long previousMillisOff9 = 0;
unsigned long previousMillisOn10 = 0;
unsigned long previousMillisOff10 = 0;
// constants won't change :
const long intervalOn9= 1000;
const long intervalOff9 = 500;
const unsigned long intervals9[] {intervalOff9, intervalOn9};
const long intervalOn10 = 2000;
const long intervalOff10 = 1000;
const unsigned long intervals10[] {intervalOff10, intervalOn10};
bool ascending = true;
int led4 = 5; //LED pin number
int led5 = 6; //LED pin number
//int ledPin9 = 9; //LED pin number
//int ledPin10 = 10; //LED pin number
int PIRA1 = A1; //PIR pin P5 on ...Layout_w_direct_230507.jpg
int PIRA2 = A2; //PIR pin P4 on ...Layout_w_direct_230507.jpg
int PIRA3 = A3; //PIR pin P3 on ...Layout_w_direct_230507.jpg
bool led4On = false; //Status of led4, set to off by default
long millisToTurnOffLed4 = 0; // This variable gets set to the time when led1 should turn off.
bool led5On = false; //Status of led5, set to off by default
long millisToTurnOffLed5 = 0; // This variable gets set to the time when led1 should turn off.
bool ledD2On = false; //Status of led1, set to off by default
long millisToTurnOffLedD2 = 0; // This variable gets set to the time when led1 should turn off.
bool ledD1On = false; //Status of led1, set to off by default
long millisToTurnOffLedD1 = 0; // This variable gets set to the time when led1 should turn off.
void setup() {
Serial.begin(115200);
Serial.println("\nLED 9?\n");
pinMode(PIRA2, INPUT_PULLUP); //setup PIRA0 as input
pinMode(PIRA1, INPUT_PULLUP); //setup PIRA1 as input
pinMode(PIRA3, INPUT_PULLUP); //setup PIR12 as input
pinMode(led4, OUTPUT); //setup led4 pin as output
pinMode(led5, OUTPUT); //setup led5 pin as output
pinMode(ledPin9, OUTPUT); //setup led1 pin as output
pinMode(ledPin10, OUTPUT); //setup led1 pin as output
}
# define PIRACTIVE LOW // i am using pushbuttons wired pulled up
void runLed4() {
digitalWrite(led4, led4On); //sets LED 4 to whichever state variable led4on says to.
bool valA3 = digitalRead(PIRA2) == PIRACTIVE; //reads PIRA5's state
if (valA3) { //This block is triggered if PIRA1 is activated
led4On = true; //turns led1 on
millisToTurnOffLed4 = millis() + 3000; //sets our stopwatch. This variable is set to the current time + 1.5 seconds. (millis() + 1500)
}
if (millis() >= millisToTurnOffLed4) { //continually checks to see if our current time ( millis() ) is equal to our "stopwatch", if so, we turn the led1 off;
led4On = false;
}
}
void runLed5() {
digitalWrite(led5, led5On); //sets LED5 to whichever state variable led2on says to.
bool valA3 = digitalRead(PIRA3) == PIRACTIVE; //reads PIRA5's state
if (valA3) { //This block is triggered if PIRA1 is activated
led5On = true; //turns led5 on
millisToTurnOffLed5 = millis() + 3000; //sets our stopwatch. This variable is set to the current time + 1.5 seconds. (millis() + 1500)
}
if (millis() >= millisToTurnOffLed5) { //continually checks to see if our current time ( millis() ) is equal to our "stopwatch", if so, we turn the led1 off;
led5On = false;
}
}
void runledPin9() {
unsigned long currentMillisOn9= millis();
if (currentMillisOn9 - previousMillisOn9 >= intervals9[ledState9])
{
// save the last time you blinked the LED
previousMillisOn9 = currentMillisOn9;
// if the LED is off turn it on and vice-versa:
if (ledState9 == LOW) {
Serial.println(" LED 9 goes ON");
ledState9 = HIGH;
} else {
Serial.println(" LED 9 goes OFF");
ledState9 = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin9, ledState9);
}
}
void runledPin10() {
unsigned long currentMillisOn10 = millis();
if (currentMillisOn10 - previousMillisOn10 >= intervals10[ledState10])
{
// save the last time you blinked the LED
previousMillisOn10 = currentMillisOn10;
// if the LED is off turn it on and vice-versa:
if (ledState10 == LOW) {
Serial.println(" LED 10 goes ON");
ledState10 = HIGH;
} else {
Serial.println(" LED 10 goes OFF");
ledState10 = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin10, ledState10);
}
}
void runLed4Descending() {
digitalWrite(led4, led4On); //sets LED 4 to whichever state variable led4on says to.
bool valA1 = digitalRead(PIRA1) == PIRACTIVE; //reads PIRA5's state
if (valA1) { //This block is triggered if PIRA1 is activated
led4On = true; //turns led1 on
millisToTurnOffLed4 = millis() + 3000; //sets our stopwatch. This variable is set to the current time + 1.5 seconds. (millis() + 1500)
}
if (millis() >= millisToTurnOffLed4) { //continually checks to see if our current time ( millis() ) is equal to our "stopwatch", if so, we turn the led1 off;
led4On = false;
}
}
void runLed5Descending() {
digitalWrite(led5, led5On); //sets LED5 to whichever state variable led2on says to.
bool valA1 = digitalRead(PIRA2) == PIRACTIVE; //reads PIRA5's state
if (valA1) { //This block is triggered if PIRA1 is activated
led5On = true; //turns led5 on
millisToTurnOffLed5 = millis() + 3000; //sets our stopwatch. This variable is set to the current time + 1.5 seconds. (millis() + 1500)
}
if (millis() >= millisToTurnOffLed5) { //continually checks to see if our current time ( millis() ) is equal to our "stopwatch", if so, we turn the led1 off;
led5On = false;
}
}
void loop() {
if (digitalRead(PIRA2) == PIRACTIVE) { // sets ascending to true if bottom sensor is tripped
ascending = true;
}
if (digitalRead(PIRA1) == PIRACTIVE) {
ascending = false;
}
if (ascending) {
runLed4();
runLed5();
}
else {
runLed4Descending();
runLed5Descending();
}
runledPin9();
runledPin10();
}
/*
Sketch to test Seeed SAMSD12 using
blink w/o delay in three separate functions
WITH SEPARATE on AND off intervals
Tested positive 240828
// constants won't change. Used here to set a pin number :
const int ledPin4 = 4; // the number of the LED pin
const int ledPin6 = 6; // the number of the LED pin
const int ledPin10 = 10; // the number of the LED pin
// Variables will change :
int ledState4 = LOW;
int ledStateOff4 = LOW;
int ledState6 = LOW;
int ledStateOff6 = LOW;
int ledState10 = LOW;
int ledStateOff10 = LOW;
unsigned long previousMillisOn4 = 0;
unsigned long previousMillisOff4 = 0;
unsigned long previousMillisOn6 = 0;
unsigned long previousMillisOff6 = 0;
unsigned long previousMillisOn10 = 0;
unsigned long previousMillisOff10 = 0;
// constants won't change :
const long intervalOn4 = 2000;
const long intervalOff4 = 500;
const unsigned long intervals4[] {intervalOff4, intervalOn4};
const long intervalOn6 = 1500;
const long intervalOff6 = 1000;
const unsigned long intervals6[] {intervalOff6, intervalOn6};
const long intervalOn10 = 1000;
const long intervalOff10 = 2500;
const unsigned long intervals10[] {intervalOff10, intervalOn10};
void setup() {
// set the digital pin as output:
pinMode(ledPin4, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin10, OUTPUT);
}
void loop() {
runLED4();
runLED6();
runLED10();
}
void runLED4() {
unsigned long currentMillisOn4 = millis();
if (currentMillisOn4 - previousMillisOn4 >= intervals4[ledState4])
{
// save the last time you blinked the LED
previousMillisOn4 = currentMillisOn4;
// if the LED is off turn it on and vice-versa:
if (ledState4 == LOW) {
ledState4 = HIGH;
} else {
ledState4 = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin4, ledState4);
}
}
void runLED6() {
unsigned long currentMillisOn6 = millis();
if (currentMillisOn6 - previousMillisOn6 >= intervals6[ledState6])
{
// save the last time you blinked the LED
previousMillisOn6 = currentMillisOn6;
// if the LED is off turn it on and vice-versa:
if (ledState6 == LOW) {
ledState6 = HIGH;
} else {
ledState6 = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin6, ledState6);
}
}
void runLED10() {
unsigned long currentMillisOn10 = millis();
if (currentMillisOn10 - previousMillisOn10 >= intervals10[ledState10])
{
// save the last time you blinked the LED
previousMillisOn10 = currentMillisOn10;
// if the LED is off turn it on and vice-versa:
if (ledState10 == LOW) {
ledState10 = HIGH;
} else {
ledState10 = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin10, ledState10);
}
}
*/