Seems I have missed something again.

Sorry folks, but I am having a lot of brain failures recently.

I've done things in other sketches like this and they work.

I feel I am going to be told that I can't call routines (functions/what ever) with MULTIPLE variables, and I can only return ONE variable.

I'll ask the obvious question/s:
What happens if the function needs multiple things?
What happens if there are more than one result?

Sorry, there are a couple of #includes not in the code.
But they aren't the problem.

(edit)
This is part of my reading a book and doing "OOP" codes. (Object Oriented Programming)
So that is why I have it set out this way.

LED_Clock.zip (2.27 KB)

You can call a function with multiple arguments

You can not return more than one value from a function.

To affect multiple variables pas in to the function a pointer to the variables and work on that. When you return the variables will have the new value. You can also return a pointer to ann array.

Thanks Grumpy.

I don't understand how to do what you explained.

Could you PLEASE give me an example of how to do that with my code?

Thanks.

Simplify life. Use global variables ??? (and drive the purists nuts)

...R

Sorry can't read your code as I am on an iPad at the moment, it dosn't do zip files.

Google for passing pointers in C

Robin2:
Simplify life. Use global variables ??? (and drive the purists nuts)

...R

Yes that is another way :slight_smile:

Giggle. :wink:

Yeah, I may have to use Global variables.

I guess I should work on how I make the functions and multiple call them.

So when I "get_time" it returns hour, minute, second.

Although the RTC library "returns" time in now.hours() now.minutes() and now.seconds().
So I would have to make my block read a variable to determine if it is Hrs, Mns, or Secs to return.

Thanks. I'll keep working on it.

Probably go with global variables for now.

(Alas this may have other problems with other codes too.)

Oh well, what's life without a challenge?

This is my MODIFIED code.

Re-written to one block.

/*
This is my sketch for a NEO PIXEL ring LED clock.
*/

//  Includes below:
#include <Wire.h>
#include <stdio.h>
#include <Adafruit_NeoPixel.h>
#include <RTClib.h> 

int rtc[7];
RTC_DS1307 RTC;             // Create RTC object


//  Define things here and set things up.
# define Loop 60
#define PIN 6    // This is defining which Arduino pin is driving the Pixel ring

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Loop, PIN, NEO_GRB + NEO_KHZ800);


//  Now you do the initial setup of things here.
//
//
//  Need work.  It is 24 bit colours.  RGB  (So "int" is not really correct)
int HR_Colour = 0x055550;
int MN_Colour = 0x550000;
int SE_Colour = 0x000055;




void setup() 
{
  // put your setup code here, to run once:
  delay(2000);          //  This is just to give you time to open the window and watch.
  Serial.begin(9600);
  Serial.println("-------------------------------");
  Serial.println("Setting up");
  
  Wire.begin();
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  int LED[Loop];
  Serial.begin(9600);
  Serial.println("Setting up");



  Serial.println("Done setting up");
  Serial.println("-------------------------------");
}

void loop() 
{
  // put your main code here, to run repeatedly: 
  //
  //  Get time
   DateTime now = RTC.now();
   int hr = now.hour();
   int mins = now.minute();
   int second_led = now.second();

  //
  //  calculate leds
   int hour_led = ((Loop/12) * hr) + (6 * (Loop/mins));
   int minute_led = mins;

  //
  //  Show LEDs
   strip.setPixelColor(hour_led,HR_Colour);
   strip.setPixelColor(minute_led,MN_Colour);
   strip.setPixelColor(second_led,SE_Colour);
   strip.show();
   



  //
  //  show alarms
  //
  
}

//==================================================================
//==================================================================
//
//    end of code
//
//==================================================================

Thoughts?

  int LED[Loop];

What is that line supposed to do?
It seems to create an array within setup() that is never used.
Maybe it should come before setup() ?

Loop is a very confusing (I'm being polite) name for a value in a programming environment where loop() is such an important part.

...R

Or skip the pointers and use references instead

Robin2:

  int LED[Loop];

What is that line supposed to do?
It seems to create an array within setup() that is never used.
Maybe it should come before setup() ?

Loop is a very confusing (I'm being polite) name for a value in a programming environment where loop() is such an important part.

...R

Granted it is confusing.

It was broken down more when I had separate blocks. Alas only being able to send/return ONE variable kind of killed that.

LED[Loop] sets up ...... Ah. I see what you mean.

That was used when I had separate blocks..... Deja vous.

Why do you say it is not right to put it in SETUP?
Granted it could go BEFORE, but why is it a problem where it is - apart from the fact it isn't used?

AWOL,
Not exactly sure which part you mean, but isn't that what was done with the hour_led, minute_led and second_led?

I can't see any references in your code - I'm confused.

It was probably used in another part which I had to delete because of the problems.

So it was completely negated in the smaller code I posted.
And I didn't remove the line because I forgot to.

lost_and_confused:
Why do you say it is not right to put it in SETUP?
Granted it could go BEFORE, but why is it a problem where it is - apart from the fact it isn't used?

Because it was not used in setup() I had assumed it was intended to be a global variable rather than a local variable within setup().

...R

Thanks.

Anyway, this is the working sketch:

http://forum.arduino.cc/index.php?topic=265294.0