almirlalicic:
Hello everybody,just read a book about c language and trying to sharpen those newley found skills in practice. (pardon my english becouse it isnt my first language).
So ive put some leds and resistors in series on a "protoboard" and the positive terminals on the pins from 2 to 12 .
Anyway ive been trying to implement a c code in the arduino ide, cuz i dont wanna copy paste digitalWrite etc a million times...So im posting my code here and if anyone can help me where did i go wrong in my c logic.
long long counter = 1000;
int main () {
int ledPin; //maybe i should have picked only one, tried several versions and this logic worked in my head the most
int oldVal;
for( oldVal=2; oldVal <= 12; oldVal++) {
ledPin=oldVal;
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
while(counter < 1000000) { //just a manual delay funct cuz the original one did not work at all
counter++;
}
}
return 0;
}
So basiclly my code for now Works this way; 1. Led on the pin2 turns on 2. After few seconds all of them(12 of them) turn on simultaneously I want my code to turn one led on, than wait a certain period of thime than turn the second one, and the third and etc.
Your code should turn each led off after the ... count loop delay and before the next is turned on? Because how else will it change?
And your counter gets from 0 to 1000000 for the first led and keeps ++ for the rest. If you use loop() then you can declare counter inside of loop() it will be a temporary variable that is made only for one run through loop() that ends when loop() does, it would not need resetting.
And since counter is declared as an int (16 bit signed on Arduino), it can't count to 1000000.
Did that book teach you about arrays?
I went to link to the page that shows simply how Arduino sketches are made (with setup() and loop() not main()) and I come back feeling that Arduino crew are Microsoft trained to make documentation ever more USELESS.