// main code: ArduinoCode.ino
///establish variables
int dial1 = A1;
int value1 = 0;
int LDRdial = A2;
int LDRdialvalue = 0;
int distancedial = A3;
int distancedialvalue = 0;
// CLASS + OBJECTS;
#include "LED.h"
//create a LED object that attach to pin
LED ledG(11);
LED ledR(10);
LED ledB(9);
// CLASS + OBJECTS;
#include "BUTTON.h"
//create a button object that attach to pin
BUTTON buttonG(13);
BUTTON buttonR(12);
BUTTON buttonB(8);
BUTTON buttonW(7);
BUTTON buttonBlack(6);
BUTTON buttonGrey(2);
// CLASS + OBJECTS;
#include "SENSOR.h"
//create a snensor object that attach to pins
SENSOR sensormotion(3, A5);
SENSOR sensordistance(4, 5);
SENSOR sensorLDR(A0, A5);
// CLASS OBJECTS;
#include "FEATURES.h"
// create a class object that attach to vaiables
FEATURES smooth(60, 1, 8); //6seconds of smooth rotation through colours
FEATURES gradual(61, 125, 1000); //6seconds of 6colour blends of RGB Dsiplay
FEATURES jump(62, 250, 2000); //6seconds of 3colour RGB display
FEATURES onofflong(63, 0, 15000); //15seconds display
FEATURES onoffshort(64, 0, 2000); //2seconds display
FEATURES onoffstrobe(65, 0, 500); //half second pulse
void setup() {
//Serial.begin(9600); ////can be activated for test and debug
pinMode(LDRdial, INPUT);
pinMode(distancedial, INPUT);
/// setting some base variable setting in case of reset.
sensorLDR.activationvalue = 10;
sensordistance.activationvalue = 200;
}
void loop() {
////main secutiry light if statement to activate light under sensor conditions
//if statement to test if LDR sensor is within activation to activate main function.
if (sensorLDR.readsensorState(sensorLDR.withinactivation(sensorLDR.getLUXconversion()))== true){
// short white LED flash of 2seconds to signal activation.
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
// Serial.print(sensorLDR.sensorState ); // can be used for testing LDR Value in debug
//do while to keep cheecking within activation of distance sensor and motion sensor state while LDR sensor is high.
do {
//button light operationall while darkness has LDR sensor activatied
buttonchecker();
if ((sensordistance.readsensorState(sensordistance.withinactivation(sensordistance.readDistanceCM())))== true){
//nested if for motion sensor so it cannot activative untill distance sensor is within range.
if ((sensormotion.readsensorState(sensormotion.getsensorState())) == HIGH){
//resulting frunction of all sensors in range, a 15 second white LED display
dialchecker();
delay (onofflong.delayRate);
}
}
}while(sensorLDR.readsensorState(sensorLDR.withinactivation(sensorLDR.getLUXconversion()))== HIGH);
}
/// grey button toget into settings mode.
while ((buttonGrey.buttonpressreaction())== true){
ledG.lightON();//greenled flash to indicate in settings mode
delay (200);
ledG.lightOFF();
delay (200);
//in setting mode red button to set light sensativity with LDRdial
if ((buttonR.buttonpressreaction())== true){
//LDR activation value = from 0 to 34, in whole numbers as it int, and twilight lux bieng around 10 lux
LDRdialvalue = analogRead(LDRdial) /30 ;
sensorLDR.activationvalue = LDRdialvalue;
//if level of light activation reached.
if (sensorLDR.readsensorState(sensorLDR.withinactivation(sensorLDR.getLUXconversion()))== true){
// short white LED flash of 2seconds to signal activation.
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay (200);
}
//exit out by holding red button untill light stops flashing.
}
//in setting mode blue button to set distance sensitivity with distancedial
if ((buttonB.buttonpressreaction())== true){
//distance activation value = from 0 to just short of 400cm. whole numbers stored only by int.
distancedialvalue = analogRead(distancedial) /2.6 ;
sensordistance.activationvalue = distancedialvalue;
//if level of distance activation reached.
if ((sensordistance.readsensorState(sensordistance.withinactivation(sensordistance.readDistanceCM())))== true){
// short white LED flash of 2seconds to signal activation.
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay (200);
}
//exit out by holding blue button untill light stops flashing.
}
//exit out by pressing grey button
}
}
////function to allow buttons to activate ligth displays
void buttonchecker (){
//using methods of GREEN LED/BUTTON objects together in if statements and loop.
//if to check green button
if ((buttonG.buttonpressreaction())== true){
// dowhile to maintain continuous loop of object method while condition is meet
do{
ledG.lightON();//led lights up
}while ((buttonG.buttonpressreaction())==true);
// reset object variable before exit once while condition isnt meet
ledG.lightOFF();
}
//using methods of RED LED/BUTTON objects together in if statements and loop.
if ((buttonR.buttonpressreaction())== true){
do{
ledR.lightON();//led lights up
}while ((buttonR.buttonpressreaction())==true);
ledR.lightOFF();
}
//using methods of BLUE LED/BUTTON objects together in if statements and loop.
if ((buttonB.buttonpressreaction())== true){
do{
ledB.lightON();//led lights up
}while ((buttonB.buttonpressreaction())==true); // cause program to loop intil only one condition allows excape
ledB.lightOFF();
}
//using methods of white FEATURE/LED/BUTTON objects together in if statements and loop.
//using methods of BLUE LED/BUTTON objects together in if statements and loop.
if ((buttonW.buttonpressreaction())== true){
do{
ledG.lightON();//led lights up
ledR.lightON();//led lights up
ledB.lightON();//led lights up
}while ((buttonW.buttonpressreaction())==true); // cause program to loop intil only one condition allows excape
ledG.lightOFF();
ledR.lightOFF();
ledB.lightOFF();
}
//using methods of white FEATURE/LED/BUTTON objects together in if statements and loop.
while ((buttonBlack.buttonpressreaction())== true){
jump.THREEcolourRotation(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
}
//using methods of white FEATURE/LED/BUTTON objects together in if statements and loop.
while ((buttonGrey.buttonpressreaction())== true){
dialchecker ();
}
}
// function for checking the dial seteting of the feature dial
void dialchecker (){
// reads dial stores the intger as 0,1,2,3,4,
value1 = analogRead(dial1) / 255;
delay (10);
// checks value interger to determine which case to run
switch (value1) {
case 1 :
//smooth colour change
smooth.THREEcolourRotation(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
break;
case 2 :
//gradual colour change
gradual.THREEcolourRotation(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
break;
case 3 :
// jump colour change
jump.THREEcolourRotation(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
break;
case 4 :
//strobotic
onoffstrobe.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay(500);
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay(500);
onoffstrobe.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay(500);
onoffshort.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
delay(500);
break;
default :
//long on white
onofflong.whitelight(ledG.getPin(), ledG.getlightVAL(), ledR.getPin(), ledR.getlightVAL(), ledB.getPin(), ledB.getlightVAL());
break;
}
}