hey everyone,
iam a beginner in arduino and coding. i buyed a book with many informations about starting with the arduino, did some experiments and finally
doesnt come forward now.
i have 16 leds connected (via 330r) to the digital outputs (pin 30-45) of my arduino mega. a momentary switch is also connected to Digitalinput 22
the goal: plug in the arduino, the first led lights up, now i want to push the momentary switch to jump to the next LED (led2) but the first one goes out. so on until the
chain reached led 16, after led 16 it starts again to count from LED 1. I MEAN, everytime a HIGH occurs at digital pin 22 the next led will go on and the previous one go off.
i tried many examples with laststate variables, delay (hundred % unusual ), millis, but that was not what i want. a high level at one input activate the next led in the array.
but damn HOW?
i know this:
for( i= o; i<16; i++)
or for(thispin=0; thispin < 45; thispin++)
i know IF, IF/else
i know int lastcount.. or something like that,
i know sensorValue but it isnt functionally with my idea.
i´ve attached my code from now .. i hope anyone can give me some suggestion in HOW TRIGGER LED AFTER LED BY AN INCOMING HIGH LEVEL
very thank you !!
int ledPin[] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
int schalterPin = 8;
int schalterStatus;
int sensorPin = A1;
int taster = 22; //doesnt know how i can start counting led after led by
int tasterstatus = 0; //pressing this button
int tasterValue = 0; //i think i need that integer
int previousTasterValue = 0; // and this one
int sensorValue;
void setup()
{
for(int i = 0; i < 16; i++)
for(int i = 15; i >= 0; i--)
pinMode(ledPin[i], OUTPUT);
pinMode(schalterPin, INPUT);
}
/*void forthback(){ // the delay is unusual but iam glad that iam able to control the rate :)
for (int i = 0; i < 16; i++)
{
sensorValue = analogRead(sensorPin);
// turn the pin on:
digitalWrite(ledPin[i], HIGH);
delay(sensorValue);
// turn the pin off:
digitalWrite(ledPin[i], LOW);
}
// loop from the highest pin to the lowest:
for (int i = 15; i >= 0; i--)
{
sensorValue = analogRead(sensorPin);
// turn the pin on:
digitalWrite(ledPin[i], HIGH);
delay(sensorValue);
// turn the pin off:
digitalWrite(ledPin[i], LOW);
}
}*/
void forth(){ // lets take this one for experimenting
for (int i = 0; i < 16; i++)
{
sensorValue = analogRead(sensorPin); // do i need to insert a IF ELSE commandline here?
digitalWrite(ledPin[i], HIGH); // how can i make it count ????
delay(sensorValue);
// turn the pin off:
digitalWrite(ledPin[i], LOW);
}
}
void loop() { // here i can switch between leds forware or forward and then backward
schalterStatus = digitalRead(schalterPin);
if(schalterStatus == HIGH)
forthback();
else
forth();
}