Can somone take a look at this code. I have i stair with led stripes in every step and a ir sensor at the top and the bottom. I am using 3 potmeters to controll delay. Pot 1 controlls time between the steps to light up. Pot 2 controlls the time between the steps to turn off. Pot 3 controlls wait time before the steps strats to turn off.
The problem is that that i have to turn pot 2 and 3 to almost 0 to not get delay when i trigging irup.
const int analogInPin1 = A0; // Analog input pin that the potentiometer is attached to
const int analogInPin2 = A1; // Analog input pin that the potentiometer is attached to
const int analogInPin3 = A2; // Analog input pin that the potentiometer is attached to
const int irup = 10; // IR Beam at the bottom of the stairs
const int irdown = 3; // IR Beam at the top of the stairs
const int allon = 4;
int sensorValueOn = 0; // value read from the pot
int sensorValueOff = 0; // value read from the pot
int sensorValueOff2 = 0; // value read from the pot
int outputValueOn = 0;
int outputValueOff = 0;
int outputValueOff2 = 0;
int led1 = 22;
int led2 = 23;
int led3 = 24;
int led4 = 25;
int led5 = 26;
int led6 = 27;
int led7 = 28;
int led8 = 29;
int led9 = 30;
int led10 = 31;
int led11 = 32;
int led12 = 33;
int led13 = 34;
int led14 = 35;
// variables will change:
int irupState = 0;
int irdownState = 0;
void setup() {
Serial.begin(9600);
// sets the digital pin as output
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(led13, OUTPUT);
pinMode(led14, OUTPUT);
// sets the digital pin as input
pinMode(irup, INPUT_PULLUP);
pinMode(irdown, INPUT_PULLUP);
pinMode(allon, INPUT_PULLUP);
}
void loop() {
// read the analog in value:
sensorValueOn = analogRead(analogInPin1);
// map it to the range of the analog out:
outputValueOn = map(sensorValueOn, 0, 1023, 100, 30000);
// read the analog in value:
sensorValueOff = analogRead(analogInPin2);
// map it to the range of the analog out:
outputValueOff = map(sensorValueOff, 0, 1023, 100, 30000);
// read the analog in value:
sensorValueOff2 = analogRead(analogInPin3);
// map it to the range of the analog out:
outputValueOff2 = map(sensorValueOff2, 0, 1023, 100, 30000);
// read the state of the ir sensor value:
irupState = digitalRead(irup);
if (irupState == 0) {
// turn LED's on:
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
delay(sensorValueOn);
digitalWrite(led3, HIGH);
delay(sensorValueOn);
digitalWrite(led4, HIGH);
delay(sensorValueOn);
digitalWrite(led5, HIGH);
delay(sensorValueOn);
digitalWrite(led6, HIGH);
delay(sensorValueOn);
digitalWrite(led7, HIGH);
delay(sensorValueOn);
digitalWrite(led8, HIGH);
delay(sensorValueOn);
digitalWrite(led9, HIGH);
delay(sensorValueOn);
digitalWrite(led10, HIGH);
delay(sensorValueOn);
digitalWrite(led11, HIGH);
delay(sensorValueOn);
digitalWrite(led12, HIGH);
delay(sensorValueOn);
digitalWrite(led13, HIGH);
delay(sensorValueOn);
digitalWrite(led14, HIGH);
}
if (irupState == 1
) {
// turn LED's off:
delay(outputValueOff2);
digitalWrite(led1, LOW);
delay(sensorValueOff);
digitalWrite(led2, LOW);
delay(sensorValueOff);
digitalWrite(led3, LOW);
delay(sensorValueOff);
digitalWrite(led4, LOW);
delay(sensorValueOff);
digitalWrite(led5, LOW);
delay(sensorValueOff);
digitalWrite(led6, LOW);
delay(sensorValueOff);
digitalWrite(led7, LOW);
delay(sensorValueOff);
digitalWrite(led8, LOW);
delay(sensorValueOff);
digitalWrite(led9, LOW);
delay(sensorValueOff);
digitalWrite(led10, LOW);
delay(sensorValueOff);
digitalWrite(led11, LOW);
delay(sensorValueOff);
digitalWrite(led12, LOW);
delay(sensorValueOff);
digitalWrite(led13, LOW);
delay(sensorValueOff);
digitalWrite(led14, LOW);
}
// print the results to the serial monitor:
Serial.print("sensor = ");
Serial.print(sensorValueOn);
Serial.print("\t output = ");
Serial.println(outputValueOn);
Serial.print("IRUP = ");
Serial.println(irupState);
Serial.print("IRDOWN = ");
Serial.println(irdownState);
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}