Hi! please consider the follwoing code:
int i,k;
int bp1=7;//button
int led0=6,led1=9,led2=10,led3=11,led4=12;
int sensorPin = A0; // input pin potentiometer
int ledpot = 5;
int sensVal = 0; // variable to store the value coming from the sensor
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
pinMode(led4,OUTPUT);
pinMode(bp1,INPUT);
}
void loop()
{
if(digitalRead(bp1,HIGH)) digitalWrite(Led0,HIGH);
else digitalWrite(Led0,LOW);
sensVal = analogRead(sensorPin);
digitalWrite(ledpot, HIGH);
delay(sensVal);
digitalWrite(ledpot, LOW);
delay(sensVal);
for(i=1;i<=4;i++)
{
if(k%4==0)
{
if(i==4) i=1;
if(i ==1) digitalWrite(Led1,HIGH); else digitalWrite(Led1,LOW);
if(i ==2) digitalWrite(Led2,HIGH); else digitalWrite(Led2,LOW);
if(i ==3) digitalWrite(Led3,HIGH); else digitalWrite(Led3,LOW);
if(i ==4) digitalWrite(Led4,HIGH); else digitalWrite(Led4,LOW);
}
k++;
}
}
Now i want to excecute the code without the use of the delay function. considering a timing of 250ms, i check by using the modulus function. but the actual result is, only the first LED reacts(stays OFF) and all the other led's on.
PLEASE ADVISE HOW TO PROCEED. I am new to arduino.
THANKS IN ADVANCE!!
EDITS: i have made the following changes: replaced 'j' by 'k'.
additonal code