Hi
I’m trying to finish my project for stairs lights. I finished the technical part but I find some diffucuties to programming the adruino uno to manage. I have some poblems with the digital pins.
I have 13 stairs wich are connect to pin (0-rx untill 12)
and the detector in the bottom and top step in the anlogic pin A2 and A3.
//declaration des pins
int ledPin= 28;
int modedepan = 30; //button to activate/disable the led striptease of test without changing color
int Bpluspin = 2; //change of luminosity decreasing
int Bmoinspin = 3; //increasing change of luminosity
int activity = 27; //led intern allowing to check the activitee of the adruino
int marche = {
2, 3, 4, 5, 6, 11, 12, 13, 14, 15, 16, 17, 18}; //outputs or are reliees the steps, on the basis of bottom in top
int marchetest = 32; //led strip de test
int capteurbas = 0; //capteur de presence en bas de l’escalier
int capteurhaut = 1; //capteur de presence en haut de l’escalier
//initialization of the mode of connection of the pines
// initialization of the variables
unsigned int Bright = 50;
int Veille = 0;
int Verrou = 0;
int activitycount = 0;
int luminositee = 0;
//parameters for the clocking
int nbrmarche = 13; //stairs number
//time of lighting of the leds
int tpsattente = 25000; //time of lighting once any celandine
int tpsallum= 98; //time of clocking of a walk
int marcheN;
void setup()
{
Serial.begin(9600); //utile au debug
pinMode(ledPin, OUTPUT); // configuration in mode left for the input/output nommee
pinMode(activity, OUTPUT);
pinMode(Bmoinspin, INPUT_PULLUP);
pinMode(Bpluspin, INPUT_PULLUP);
pinMode(capteurbas, INPUT_PULLUP);
pinMode(capteurhaut, INPUT_PULLUP);
pinMode(modedepan, INPUT_PULLUP); // allows to light all the led striptease for a breakdown service
for (int marcheN = 0; marcheN < nbrmarche; marcheN++) {
pinMode(marche[marcheN], OUTPUT);
}
}
//program
void loop()
{
luminositee = analogRead(0); //acquisition luminositee
//verif activite du teensy
activitycount++;
if ( activitycount == 100)
{
digitalWrite(activity, HIGH);
}
if ( activitycount == 100)
{
digitalWrite(activity, LOW);
activitycount = 0;
}
//
//mode depannage
if (digitalRead (modedepan) == LOW && Verrou == 0) //condition of locking
{
delay(1000);
Verrou = 1;
for (int marcheN = 0; marcheN < nbrmarche; marcheN++) // condition of the forcing of lighting
{
// allumer la marche
digitalWrite(marche[marcheN], HIGH);
}
digitalWrite(marchetest, HIGH);
}
if ((digitalRead (modedepan) == LOW )&& (Verrou == 1)) //condition of unlocking and extinction of the forcing of lighting
{
delay(1000);
Verrou = 0;
for (int marcheN = 0; marcheN < nbrmarche; marcheN++)
{
digitalWrite(marche[marcheN], LOW);
}
digitalWrite(marchetest, LOW);
}
// turn on the light in case going up
if ((digitalRead (capteurbas) == LOW) && luminositee <= 400 && Verrou == 0)
{
for (int marcheN = 0; marcheN < nbrmarche; marcheN++)
{
//turn on the light
digitalWrite(marche[marcheN], HIGH);
delay(tpsallum);
}
delay(tpsattente);
for (int marcheN = 0; marcheN < nbrmarche; marcheN++)
{
digitalWrite(marche[marcheN], LOW);
delay(tpsallum);
}
}
// turn on the light in case going down
if ((digitalRead (capteurhaut) == LOW) && luminositee <= 400 && Verrou == 0)
{
for (int marcheN = nbrmarche - 1; marcheN >= 0; marcheN–)
{
// Turn on the light
digitalWrite(marche[marcheN], HIGH);
delay(tpsallum);
}
delay(tpsattente);
for (int marcheN = nbrmarche - 1; marcheN >= 0; marcheN–)
{
digitalWrite(marche[marcheN], LOW);
delay(tpsallum);
}
}
//debug
/*
Serial.print(“Bright =”);
Serial.println(Bright);
delay(200);
Serial.print(“Code R =”);
Serial.println(CodeR);
delay(200);
*/
}