Go Down

Topic: Help needed for a beginner (Read 2217 times) previous topic - next topic

Gavincol78

I am trying to get a WS2812 60 LED ring to work as a clock but because the DIN runs in reverse (counter-clockwise) each of the LED clock sketches I have tried shows the clock in reverse (just like the novelty backwards clocks).

I was advised on another thread to change the array so that it works in reverse (which would make my ring work correctly in a clockwise manner) yet I cannot figure out how to create this adjustment in a code I have downloaded.

The main code I am trying to use is from http://forum.arduino.cc/index.php?topic=265294.0

larryd

#1
Feb 25, 2016, 10:07 pm Last Edit: Feb 25, 2016, 10:08 pm by LarryD
I did something like this for a similar project.
You will have to make changes to your code:

  //========================
  //Correction needed to get Clock Wise operation
  byte secondHandCW = 59 - secondHand;
  byte minuteHandCW = 59 - minuteHand;
  byte hourHandCW   = 59 - hourHand;
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Gavincol78

I did something like this for a similar project.
You will have to make changes to your code:

  //========================
  //Correction needed to get Clock Wise operation
  byte secondHandCW = 59 - secondHand;
  byte minuteHandCW = 59 - minuteHand;
  byte hourHandCW   = 59 - hourHand;
I try that in Arduino 1.6.7 and can't figure out where to place that code and keep getting this error

Arduino: 1.6.7 (Windows 10), Board: "Arduino Nano, ATmega328"

LED_Clock5:27: error: 'secondHand' was not declared in this scope

   byte secondHandCW = 59 - secondHand;

                            ^

LED_Clock5:28: error: 'minuteHand' was not declared in this scope

   byte minuteHandCW = 59 - minuteHand;

                            ^

LED_Clock5:29: error: 'hourHand' was not declared in this scope

   byte hourHandCW   = 59 - hourHand;

                            ^

exit status 1
'secondHand' was not declared in this scope

larryd

#3
Feb 26, 2016, 12:14 am Last Edit: Feb 26, 2016, 12:15 am by LarryD
Those were my variables names, you will have to substitute your names.

But, the point here is you must:

59 - yourVariables
to get things to go clockwise.

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

larryd

For example:
if the variable is
0 then 59-0=59

if it is 59
59-59=0

if it was 10
59-10=40

etc.
.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Gavincol78

#5
Feb 26, 2016, 12:38 am Last Edit: Feb 27, 2016, 02:29 am by Gavincol78
I see the code for the pixel colours and then this code to 'draw' the pixels would adjustments be in there

Code: [Select]
/*----------------  Draw SECOND HAND on clock ----------------*/
  strip.setPixelColor(second_led,SE_Colour);
//   strip.setPixelColor(second_led,SE_Colour+THIS_LED);
//   strip.setPixelColor(second_led-1,THIS_LED);
  if (new_minute == 1)
  {
    //new_minute = 0;
//     strip.setPixelColor(minute_led-1,MN_Colour/50);
  }
 /*----------------  Draw MINUTE HAND on clock ----------------*/
  //strip.setPixelColor(minute_led,MN_Colour);
  //  MN_Fade for fading.
  strip.setPixelColor(minute_led,MN_R,MN_G,MN_B);
  strip.setPixelColor(minute_led+1, MN_R,     (MN_G * (second_led*10/6)/100)      , MN_B);
  strip.setPixelColor(minute_led-1, MN_R,     (MN_G * (100-(second_led*10/6))/100)      , MN_B);
 /*----------------  Draw HOUR HAND on clock ----------------*/
  strip.setPixelColor(hour_led,HR_R,HR_G,HR_B);
  //strip.setPixelColor((hour_led-1)%LED_Loop,HR_R/HR_Fade,HR_G,HR_B/HR_Fade);
  //strip.setPixelColor((hour_led+1)%LED_Loop,HR_R/HR_Fade,HR_G,HR_B/HR_Fade);
/*
  strip.setPixelColor(hour_led,HR_Colour);
  strip.setPixelColor((hour_led-1)%LED_Loop,HR_Colour);
  strip.setPixelColor((hour_led+1)%LED_Loop,HR_Colour);
*/  

  if (second_led > minute_led)
  {
    new_minute = 0;
  }

/*
 if (second_led != argh)
 {
    Led_Flag = 0;
    argh = second_led;

larryd

#6
Feb 26, 2016, 01:07 am Last Edit: Feb 26, 2016, 01:09 am by LarryD
I am unable to try this now, but you could try:
strip.setPixelColor(59 - second_led,SE_Colour);
.
.
.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Gavincol78

I am unable to try this now, but you could try:
strip.setPixelColor(59 - second_led,SE_Colour);
.
.
.
Thank you so much.

Although probably somewhere else in the code this method doesn't quite work with the second hand it has worked very well doing that adjustment on the minutes and hours (59 -minute_led and 59 -hour_led).

The slight glitch I now have with the second hand is that with 59 -minute_led is that I get 1 of 2 glitches 1st being I get 2 second hands, 1 going counter-clockwise and working how it should and the other slowly turning on each led. The 2nd glitch is that instead of having a gradient 4 pixel second hand going clockwise the led's slowly fill up which is not desirable.

So I have left the second hand code as is which kind of looks interesting having a counter-clockwise second hand whilst the hour and minute hands are going clock wise.

larryd

You have to use the same adjustment for minutes an hours.

Erase the array after setting pixels.
This prevents filling up.
Something similar to this:
for(byte X = 0; X < 60; X++) { clear this array location}
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Gavincol78

You have to use the same adjustment for minutes an hours.

Erase the array after setting pixels.
This prevents filling up.
Something similar to this:
for(byte X = 0; X < 60; X++) { clear this array location}
The minutes and hours work great with new adjustment but for some reason somewhere else in the code is conflicting with the adjustment for the seconds and as it is now 2am here in the UK I will re-approach the code sometime tomorrow or during the weekend. But thank you so much for your help it has been much appreciated.

https://youtu.be/JpFQWiBAdD4

Gavincol78

#10
Feb 26, 2016, 07:09 pm Last Edit: Feb 27, 2016, 02:30 am by Gavincol78
I didn't want to add this on the other thread.


I can get the seconds to go the correct way but instead of having the usual moving 4 pixels it creates a long line of pixels or I get 2 sets of seconds the original 4 pixels going the normal way + the previously mentioned way.

And that is without adjusting any other part of the code but there is also this part of the code to take into consideration which from my experiments last night did affect the way the correction worked.

For some reason when I just add the modification in the part previously advised I get the 2 sets of second hands, and if I play around with the below code I can get 1 set of the second hands going in the correct direction but create a long line of 'pixels' instead of normal one even if I add the (59 -second_led) to each part of the below code or just '//' the lines out

Code: [Select]
//
 //  Show LEDs            ------------------   Main loop here -----------------

  //  Keep this at the top so it doesn't mess up any other settings when LEDs are
  //  turned on.
  strip.setPixelColor(second_led-1,SE_Colour/2);
  strip.setPixelColor(second_led-2,SE_Colour/4);
  strip.setPixelColor(second_led-3,SE_Colour/8);
  strip.setPixelColor(second_led-4,SE_Colour/16);
  strip.setPixelColor(second_led-5,0);

//  Now start setting LEDs below here.
 //

  if (second_led == 0)
  {
     strip.setPixelColor(LED_Loop-1, SE_Colour/2);
     strip.setPixelColor(LED_Loop-2,SE_Colour/4);
     strip.setPixelColor(LED_Loop-3,SE_Colour/8);
     strip.setPixelColor(LED_Loop-4,SE_Colour/16);
     strip.setPixelColor(LED_Loop-5,0);
     new_minute = 1;
  }
  if (second_led == 1)
  {
     strip.setPixelColor(second_led-1, SE_Colour/2);
     strip.setPixelColor(LED_Loop-1, SE_Colour/4);
     strip.setPixelColor(LED_Loop-2,SE_Colour/8);
     strip.setPixelColor(LED_Loop-3,SE_Colour/16);
     strip.setPixelColor(LED_Loop-4,0);
  }
  if (second_led == 2)
  {
     strip.setPixelColor(second_led-1, SE_Colour/2);
     strip.setPixelColor(second_led-2, SE_Colour/4);
     strip.setPixelColor(LED_Loop-1, SE_Colour/8);
     strip.setPixelColor(LED_Loop-2,SE_Colour/16);
     strip.setPixelColor(LED_Loop-3,0);
  }
  if (second_led == 3)
  {
     strip.setPixelColor(second_led-1, SE_Colour/2);
     strip.setPixelColor(second_led-2, SE_Colour/4);
     strip.setPixelColor(second_led-3, SE_Colour/8);
     strip.setPixelColor(LED_Loop-1,SE_Colour/16);
     strip.setPixelColor(LED_Loop-2,0);
  }
  if (second_led == 4)
  {
     strip.setPixelColor(second_led-1, SE_Colour/2);
     strip.setPixelColor(second_led-2, SE_Colour/4);
     strip.setPixelColor(second_led-3, SE_Colour/8);
     strip.setPixelColor(second_led-4,SE_Colour/16);
     strip.setPixelColor(LED_Loop-1,0);
  }

larryd

Take this one step at a time.
Get the second hand working first, disable the tail of the second hand.
Once you are happy with the movement of the three hands then add the second hand tail.
.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Gavincol78

Take this one step at a time.
Get the second hand working first, disable the tail of the second hand.
Once you are happy with the movement of the three hands then add the second hand tail.
.
The hours and minutes was easy they sorted themselves out and accepted the code.

I have just spent the past 90 minutes trying to iron out the issue with the seconds and finally nailed it and now I have got 1 lit led and what looks like a black led turning off the trail.

Don't ask me how I managed to do this all I know is that for the second hand I have 2 leds active 1 to turn on the second hand and 1 to turn it off and I don't know if it suppose to do that or not I just tested it and it worked lol.


   strip.setPixelColor(58 -second_led,SE_R,SE_G,SE_B);

   strip.setPixelColor(59 -second_led,SE);

Gavincol78

Go and read the instructions, then go back and modify each of your posts (use the "More --> Modify" option to the bottom right of the post) to mark up the code as such so we can examine it conveniently and accurately.

Done, thank you for advising me that as I am new here and didn't notice the 'Instructions' part and before you think I maybe some kid I am actually 38 and very rarely use forums.

Go Up