Simple code not working as expected- suggestions why?

In the process of writing a larger program, I progressively cut it down to check that things are working as I want. The code below contains some things which are not required for ths simple program,and so have been disabled, but which will be required later.

I was expecting to see on the Serial Monitor

setup
loop
averageLTC2305
loop
averageLTC2305
etc.

Instead all I see is

setup
loop
loop
loop
etc

There must be something which I am missing (or do not know) here- but I cannot see it.

Please..... Thank you.

include "Wire.h"
//#define LTC2305address 0x08 // with pins AD0, AD1 set to GND, the device address is 0x08

byte aa = 0;
int aaTot = 0;
byte bb = 0;
int bbTot = 0;
byte dd;
int cc,ee;
int count;

void setup()
{
Wire.begin(); // wake up I2C bus
Serial.begin(9600);

Serial.print(" setup");
//Serial.print(count);
Serial.print("\t");
}

void loop()
{
void averageLTC();
Serial.print(" loop");
Serial.println();

//void showResult();
}

void averageLTC()
{
Serial.print("averageLTC2305 ");
Serial.println();
delay(1000);
}

Remove the void in bold from here.

void loop()
{
void averageLTC();
Serial.print(" loop");

You're not calling averageLTC() from loop, you keep re-dcelaring it. Lose the "void"...

void loop()
{
  [s]void [/s]averageLTC();
  Serial.print(" loop");
  Serial.println()

edit.... just like HM said 8)

Thank you both- silly again.

gerrymcc:
In the process of writing a larger program, I progressively cut it down to check that things are working as I want.

This sounds like it is back to front.

Get all the little parts working separately and later join them into a big project.

...R

Robin2:

gerrymcc:
In the process of writing a larger program, I progressively cut it down to check that things are working as I want.

This sounds like it is back to front.

Get all the little parts working separately and later join them into a big project.

...R

That's the coward's way Robin 8) . Go big or Go home......

Robin- This is my second program following your methodology. (First one worked well.) What I have as "void averageLTC()" is the first of what should be several sub-sectional "voids". When I first stared this "averageLTC()" void, I had many more lines, and doing more things, but it was not working. So, as part of trying to work out what was happening, I progressively commented out lines, checking steps within the "void averageLTC()" and using the Serial Monitor to check where and what was happening. This small section seems to show me that it is not stepping out of "loop", into "averageLTC()", doing something simple as proof of this step (just printing the text for the present), and then returning to the main "loop". Utimately, there will be several more voids, doing other parts of the overall project, but each stepped to, from "loop". Do I have the right idea here?

Utimately, there will be several more voids

No there won't. There will be several more functions which, if declared void, will not return a value to the place they were called from.

Have you got your test program working now ?

I have to say, "no". This is a simple building block for my project- which will be significantly expanded. I have previously followed Robin's 9 post tutorial, and was happy with the way things work from that- which uses many 'void xxx()". I was commencing to structure this project based on that format. In some ways, I blame my parents for not producing me already conversant in "Arduino speak". The more I read about Arduino programming, the more I am becoming confused with the structure of this language. Five authors, ten ideas

I think Lewis Carrol summed up my feelings in "Through the Looking Glass":
"When I use a word," Humpty Dumpty said, in a rather scornful tone, "it means just what I choose it to mean -- neither more nor less."
"The question is," said Alice, "whether you can make words mean so many different things."
"The question is," said Humpty Dumpty, "which is to be master --that's all."

gerrymcc:
Robin- This is my second program following your methodology. ?

Sorry, I am not good at keeping in touch with my disciples :slight_smile:

When you said "In the process of writing a larger program," I assumed you were not yet a signed up member.

Can you put the troublesome function in a short sketch that has the bare minimum of other stuff. That should make it much easier to focus on what matters?

...R

The more I read about Arduino programming, the more I am becoming confused with the structure of this language

Referring to a function as a void has nothing to do with the structure of the language, it is just wrong.

Would you call this function an int ?

int twice(int number)
  {
    return number + number;
  }

Below is the beginnings of the project which has created my issue, set out in the form espoused by Robin2 in his excellent 9 post series "Planing and Implementing an Arduino Program".

I have had a stand alone program working to read the LTC2305 ADC via the I2C bus. But when I put this code into this larger program, it was not behaving as expected. Putting the I2C code into this larger program was the first step. It seemed to me that the ADC was not being read. Adding Print statements and using the Serial Monitor was the way I went about troubleshooting this problem. Progressively, I removed the I2C code, until I had simple Print statements to follow the steps of the program. This is where I am at.

#include "Wire.h"
void setup()
{
  Wire.begin(); // wake up I2C bus
  Serial.begin(9600);
  Serial.print(" setup");
  Serial.print("\t");
}
void loop()
{
  Serial.print(" loop");
  Serial.println();
  void localRemote();
  void initialiseLcdDisplay();
  void readAverageLTC2305();
  void readUsbRemoteSetting();
  void setTuneYig();
  void checkYigLocked();
  void updateLcdDisplay();
  void updateAtms();
}

void localRemote()// check Local Remote switch,light Remote LED if appropriate
{
}

void initialiseLcdDisplay()// Set up on LCD display "Freq", "GHz", generate "approx" character within display, "Tuning", "V"
{
}

void readAverageLTC2305()// If in Local mode, read manual pot 10 times with LTC2305 and average, make Manual setting number available
{
  Serial.print("readAverageLTC2305 ");
  Serial.println();
}

void readUsbRemoteSetting()//If in Remote, read USB port frequency; convert to equivalent ADC setting number; make available as setting Number
{
}

void setTuneYig()//Set LTC2631 I2C ADC to 000 input; enable output; set with tuning number, enable output. (makes YIG tune from one direction only)
{
}

void checkYigLocked()// Check if YIG locked. If unlocked, increase or decrease number by 10 and retune; check for lock. When locked, set "Lock" for display use
{
}

void updateLcdDisplay()// update diplay to current Frequency and tuning voltage
{
}

Delta_G:
You're still making the same mistake.

You've declared a function called averageLTC (and several others) but when you try to call them you keep sticking the word void in front of them again.

Have you read this?

You just gave me an idea for a new trap.

void loop()
{
  Serial.print(" loop");
  Serial.println();
  void localRemote();
  void initialiseLcdDisplay();

You only put void (or int, or whatever) before the function name when you are defining the function and NOT when you are calling the function. That is how the compiler knows the difference. So the above snippet should be

void loop()
{
  Serial.print(" loop");
  Serial.println();
  localRemote();
  initialiseLcdDisplay();

Also you should be conscious that the line Serial.println() is exactly the same sort of thing as the line localRemote() - both are just function calls. The only difference is that you wrote the latter function.

...R