Learning the language....

I am learning the language of Arduino. In doing so, I am trying several methods of data output. To learn this, I have a simple sketch I need to answer my question.
Using the Blink program. I want to be able to blink the LED 8 times, and do it in different ways of control.

I have tried a couple of methods, using “IF” and “FOR”, but I get no change, the LED blinks continuously. Now, I am good at electronics, just not up to speed on programming C. I am sorta dumb, so please don’t make fun of my sketch, just tell me how to do this more efficiently, and correctly. It compiled without errors, just didn’t do the job I was trying to do. This helps me learn the “Control” commands, and how to format them correctly. I think that is the issue here, but, not sure. Can ya’ll please help me out?

Here is one of my programs:

void setup() {

pinMode(LED_BUILTIN, OUTPUT); // put your setup code here, to run once:


void loop() {
int i; // put your main code here, to run repeatedly:

i == 0;

do {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(250); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
} while (i <= 8);




i == 0;Compares the value of i to zero, and throws away the result of the comparison (and because i is local to loop() and unitialised, the value of i is indeterminate anyway) Try i = 0; to assign zero to i. Better yet, initialise it when and where you define it, at the top of loop().

Ok, I looked it over. I am at a loss. I know I am not writing it correctly, but, I cannot figure out what I hsvr to do to make it correct. I thank you for tasking me, and such, but, I want to learn quicker. Please, at the risk of sounding completely stupid, just tell me what my mistakes were. I learn faste that way.

Many Thanks…

Retired_Phart… lol!!!

Let’s rewrite the “code”

int LED_timer = 1000, // set on / off time in mS

void loop() {
int i; // put your main code here, to run repeatedly:
i == 0;


int Counter = 0; //initialize blink counter

// turn LED on/off - 10 times
do {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on - this is little redundant - HIGH is the voltage level)
delay(LED_timer); // keep the LED on wait for a second is silly and does not match the code using global variable gains flexibility - you can change it in ONE place - and avoids the comment mismatch
digitalWrite(LED_BUILTIN, LOW); // turn the LED off still redundant by making the voltage LOW
delay(LED_timer); // keep the LED off wait for a second

// } while (i <= 8); actually logical error - the value of i newer changes in the do / while
or maybe just typo

} while (Counter++ != 10 ) ; // blink the LED 10 times

delay(x); / / after x pause start over


In short - first read what the loop () is doing - looping.
Comment you code describing what it actually does - turns the LED on / off
Match your comments with code - I know that is easier to say than done - but…
Use meaningful names ( to you ) for variables - single characters are hard to find and debug.
If the variable is used more than once - declare / define it instead of retyping it over and over.
Keeps typos away.

Before somebody gets bent out of shape again - I am deliberately NOT using code tags , the purpose of my post
is to demonstrate how to accomplish the task , not how to cut and paste.

...and that, children is why we use code tags. After over 100 posts, I would have thought @232 would have picked that up.

I could edit them in, but I leave it here, as a kind of gibbet.

First, read Nick Gammon’s post at the top of this Forum on how to properly post source code using code tags:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);       // put your setup code here, to run once:


void loop() {
int i;                              // put your main code here, to run repeatedly:


do {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
} while (i <= 8);


You have a while loop inside loop(), which seems redundant. What if you changed things to:

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);       // put your setup code here, to run once:

  Serial.begin(9600);                 // Serial object to let us "see" stuff...


void loop() {
  static int i = 0;                  // static keyword means this statement is executed only once at load time

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                        // wait for a quarter second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second

  if (i % 8 == 0 && i > 0) {         // Only pause every 8 times
    Serial.println("Pass completed");


Now, walk through each line and ask what it does to determine how the code works. Also, make sure your comments really do what you say. The first delay() is only a quarter second.

I am deeply humbled by your help, and consideration. I had envisioned it would have a simpler solution, but, alas, I am so dumb, I couldn't see it!!! Thank you for pointing this out to me. I understand what was done now, and I was trying to over simplify a routine, for a learning experience. I know I tried something a bit over my head to start, but, I always dive in head first. I learn better that way, I guess. I am reading the Arduino Programming book, from Sam's, and it is not able to give me the in depth answers I am looking for.

My goal, is to create a program, to read several devices, actively store the data on a mini-SD card, for analysis after its deployment and completion of it's use for each deployment. I am adequate at designing the hardware. I need to get EXTREMELY more efficient, and better at the software, and programming. I will make it, I will just have to be diligent in my learning curve with the "C" language use here.

Just a question about a future routine... I know I am WAY ahead of myself, but, I have the hardware just about ready, and I need to stay focused on the end result. Here is the question -- If I have several, shall we say 4 devices to be read, and can each device have a set spot on the SD card storage, so it is easily accessed, and not over storing data? Like a file folder, as an example? I do NOT want streamed data on the card, but, start, mid range, end of max increase of data.

I believe most of my sensors are serial data communication. I have this process in using the "KISS" principle, so I am going to assume there are already routines written for most of these devices, and all I need is to modify each to accomplish the desired data acquisition.

Again, folks, I thank you for being so forthright, and helpful to a newbie programmer, and I hope I NEVER make myself look as stupid as I feel about this extremely talented group of people, who show their outstanding talent, in this new age of programmable controllers.

Bless all of who looked, took time to answer, and helped me off to start thinking more and deeper on the methods I need to learn!!!!

MANY, MANY, thanks!!!


Welcome Phart

Start learning buy mastering all examples that comes with the IDE.


Arduino links.

For many Arduino PDF document links: Google >>>- - - - > arduino filetype: pdf Or https://www.google.ca/search?q=arduino+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=arduino+filetype%3A+pdf&aqs=chrome..69i57j69i65.1385j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8

Google >>>- - - - > C++ filetype: pdf Or https://www.google.ca/search?q=c%2B%2B+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=c%2B%2B+filetype%3A+pdf&aqs=chrome..69i57.22790j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8



Watch these: https://m.youtube.com/watch?v=CbJHL_P5RJ8




Some things to read: