Epoxy clock code

I am having trouble with this project epoxy clock. I had thought i finished it and then come to find out the hour hand is going backwards. Unfortunately i cannot reverse the leds because the clock already has epoxy on it. Only other thing i can do is change the code where it works correctly. The project is on this website if anyone has any ideas to help me get this clock working correctly would be helpful. It is a project for my microprocessors class and is due in 2 weeks.

Thank you,

Brandon

#include <DS3231.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN            5
#define PIN2           7


#define NUMPIXELS      60
DS3231  rtc(SDA, SCL);
Time  t;
int hr;
int mnt;
int sc;
char data;
char color_select;
int h_red_deger=255;
int h_green_deger=0;
int h_blue_deger=0;
int m_red_deger=0;
int m_green_deger=255;
int m_blue_deger=0;
int s_red_deger=255;
int s_green_deger=255;
int s_blue_deger=0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(12, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(12, PIN2, NEO_GRB + NEO_KHZ800);


int delayval = 10; 

void setup() {
  Serial.begin(9600);
   rtc.begin();

#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
  pixels2.begin();
  strip.begin();
  strip.show();
  strip2.begin();
  strip2.show();
//
}

void loop() {

  while(Serial.available() > 0) // balant kuruluyken
 {
  delay(10);
  char c = Serial.read();
  data=c;
    if(data=='m')
    { 
      data=' ';
      t = rtc.getTime();
      hr=t.hour;
      mnt=t.min;
      sc=t.sec;
      while(data!='m')
      { 
        data=Serial.read();
        if(data=='+')
          {
           hr++;
          }
        if(data=='-')
          {
           hr--;
          }
         for(int i=0;i<12;i++){pixels2.setPixelColor(i, pixels2.Color(0,255,10));}
         pixels2.show();
         if(hr>=12){hr=hr-12;}
         if(hr<0){hr=hr+12;}
         pixels2.setPixelColor(hr, pixels2.Color(255,0,0));
         pixels2.show();
         delay(100);
         pixels2.setPixelColor(hr, pixels2.Color(0,0,0));
         pixels2.show();
         delay(100);
       }
      rtc.setTime(hr,mnt,sc);
      if(data=='m')
      {
         data=' ';
         t = rtc.getTime();
         hr=t.hour;
         mnt=t.min;
         sc=t.sec;
         while(data!='m')
           { 
             data=Serial.read();
             if(data=='+')
             {
              mnt++;
              if(mnt==60)
              {mnt=0;}
              }
             if(data=='-')
             {
              if(mnt==0)
              {mnt=60;}
      
              mnt--;
             }
              for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(0,0,0));}
              for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(25,25,255));k=k+4;}
      
               pixels.setPixelColor(mnt, pixels.Color(0,250,0));
               pixels.show();
               delay(100);
               pixels.setPixelColor(mnt, pixels.Color(0,0,0));
               pixels.show();
               delay(100);
              }
         }
    
          rtc.setTime(hr,mnt,sc);
           data=' ';
        }




        if(data=='H')
      { 
       color_select=data;
     }
     if(data=='M')
      { 
       color_select=data;
     }
     if(data=='S')
      { 
       color_select=data;
     }
     if(data=='A')
      { 
      data=' ';
      colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
      }
      if(data=='r'&&color_select=='H')
      { 
          h_red_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
    
        
      }     
        
         if(data=='g'&&color_select=='H')
      { h_green_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
        }
        if(data=='b'&&color_select=='H')
      { 
         h_blue_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
        }



 if(data=='r'&&color_select=='M')
      { 
          m_red_deger=Serial.parseInt();
          pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
  pixels.show();
    
        
      }     
        
         if(data=='g'&&color_select=='M')
      { m_green_deger=Serial.parseInt();
          pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
         pixels.show();
        }
        if(data=='b'&&color_select=='M')
      { 
         m_blue_deger=Serial.parseInt();
         pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
         pixels.show();
        }


if(data=='r'&&color_select=='S')
      { 
          s_red_deger=Serial.parseInt();
          pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
  pixels.show();
    
        
      }     
        
         if(data=='g'&&color_select=='S')
      { s_green_deger=Serial.parseInt();
          pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
         pixels.show();
        }
        if(data=='b'&&color_select=='S')
      { 
         s_blue_deger=Serial.parseInt();
         pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
         pixels.show();
        }



        
      
 }
           t = rtc.getTime();
           hr=t.hour;
           mnt=t.min;
           sc=t.sec;

  
  pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger)); 
  pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
  pixels.show();
   
  for(int i=0;i<12;i++){
    if(i==hr)
    {i++;}
    pixels2.setPixelColor(i, pixels2.Color(0,0,0));}
  pixels2.show();
  if(hr>=12){hr=hr-12;}
  pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger,h_blue_deger));
  pixels2.show();
  delay(10);
  pixels.setPixelColor(sc, pixels.Color(0,0,0));
  for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(0,0,0));}
  for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(10,10,10));k=k+4;}
  pixels.setPixelColor(mnt, pixels.Color(0,0,0));
  pixels.show();
  
   


}













void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
   
    strip2.setPixelColor(i, c);
    strip2.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
      strip2.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip2.show();
   
    strip.show();
    delay(wait);
  }
}

So you fixed the problem in epoxy before testing. Brilliant! Guess that means you work some late nights on the fix. If you expected any help here, you would have read how to use the forum and would have at least posted the code here, properly, so someone might even read it.

Paul

Sorry for code not being proper. Here is most of the code. Not letting me paste all the code.

#include <DS3231.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN            5
#define PIN2           7


#define NUMPIXELS      60
DS3231  rtc(SDA, SCL);
Time  t;
int hr;
int mnt;
int sc;
char data;
char color_select;
int h_red_deger=255;
int h_green_deger=0;
int h_blue_deger=0;
int m_red_deger=0;
int m_green_deger=255;
int m_blue_deger=0;
int s_red_deger=255;
int s_green_deger=255;
int s_blue_deger=0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(12, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(12, PIN2, NEO_GRB + NEO_KHZ800);


int delayval = 10; 

void setup() {
  Serial.begin(9600);
   rtc.begin();

#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
  pixels2.begin();
  strip.begin();
  strip.show();
  strip2.begin();
  strip2.show();
//
}

void loop() {

  while(Serial.available() > 0) // balant kuruluyken
 {
  delay(10);
  char c = Serial.read();
  data=c;
    if(data=='m')
    { 
      data=' ';
      t = rtc.getTime();
      hr=t.hour;
      mnt=t.min;
      sc=t.sec;
      while(data!='m')
      { 
        data=Serial.read();
        if(data=='+')
          {
           hr++;
          }
        if(data=='-')
          {
           hr--;
          }
         for(int i=0;i<12;i++){pixels2.setPixelColor(i, pixels2.Color(0,255,10));}
         pixels2.show();
         if(hr>=12){hr=hr-12;}
         if(hr<0){hr=hr+12;}
         pixels2.setPixelColor(hr, pixels2.Color(255,0,0));
         pixels2.show();
         delay(100);
         pixels2.setPixelColor(hr, pixels2.Color(0,0,0));
         pixels2.show();
         delay(100);
       }
      rtc.setTime(hr,mnt,sc);
      if(data=='m')
      {
         data=' ';
         t = rtc.getTime();
         hr=t.hour;
         mnt=t.min;
         sc=t.sec;
         while(data!='m')
           { 
             data=Serial.read();
             if(data=='+')
             {
              mnt++;
              if(mnt==60)
              {mnt=0;}
              }
             if(data=='-')
             {
              if(mnt==0)
              {mnt=60;}
      
              mnt--;
             }
              for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(0,0,0));}
              for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(25,25,255));k=k+4;}
      
               pixels.setPixelColor(mnt, pixels.Color(0,250,0));
               pixels.show();
               delay(100);
               pixels.setPixelColor(mnt, pixels.Color(0,0,0));
               pixels.show();
               delay(100);
              }
         }
    
          rtc.setTime(hr,mnt,sc);
           data=' ';
        }




        if(data=='H')
      { 
       color_select=data;
     }
     if(data=='M')
      { 
       color_select=data;
     }
     if(data=='S')
      { 
       color_select=data;
     }
     if(data=='A')
      { 
      data=' ';
      colorWipe(strip.Color(255, 0, 0), 50); // Red
  colorWipe(strip.Color(0, 255, 0), 50); // Green
  colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
  // Send a theater pixel chase in...
  theaterChase(strip.Color(127, 127, 127), 50); // White
  theaterChase(strip.Color(127, 0, 0), 50); // Red
  theaterChase(strip.Color(0, 0, 127), 50); // Blue

  rainbow(20);
  rainbowCycle(20);
  theaterChaseRainbow(50);
      }
      if(data=='r'&&color_select=='H')
      { 
          h_red_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
    
        
      }     
        
         if(data=='g'&&color_select=='H')
      { h_green_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
        }
        if(data=='b'&&color_select=='H')
      { 
         h_blue_deger=Serial.parseInt();
          pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger, h_blue_deger));
          pixels2.show();
        }



 if(data=='r'&&color_select=='M')
      { 
          m_red_deger=Serial.parseInt();
          pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
  pixels.show();
    
        
      }     
        
         if(data=='g'&&color_select=='M')
      { m_green_deger=Serial.parseInt();
          pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
         pixels.show();
        }
        if(data=='b'&&color_select=='M')
      { 
         m_blue_deger=Serial.parseInt();
         pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
         pixels.show();
        }


if(data=='r'&&color_select=='S')
      { 
          s_red_deger=Serial.parseInt();
          pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
  pixels.show();
    
        
      }     
        
         if(data=='g'&&color_select=='S')
      { s_green_deger=Serial.parseInt();
          pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
         pixels.show();
        }
        if(data=='b'&&color_select=='S')
      { 
         s_blue_deger=Serial.parseInt();
         pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger));
         pixels.show();
        }



        
      
 }
           t = rtc.getTime();
           hr=t.hour;
           mnt=t.min;
           sc=t.sec;

  
  pixels.setPixelColor(sc, pixels.Color(s_red_deger,s_green_deger,s_blue_deger)); 
  pixels.setPixelColor(mnt, pixels.Color(m_red_deger,m_green_deger,m_blue_deger));
  pixels.show();
   
  for(int i=0;i<12;i++){
    if(i==hr)
    {i++;}
    pixels2.setPixelColor(i, pixels2.Color(0,0,0));}
  pixels2.show();
  if(hr>=12){hr=hr-12;}
  pixels2.setPixelColor(hr, pixels2.Color(h_red_deger,h_green_deger,h_blue_deger));
  pixels2.show();
  delay(10);
  pixels.setPixelColor(sc, pixels.Color(0,0,0));
  for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(0,0,0));}
  for(int k=0;k<60;k++){pixels.setPixelColor(k, pixels.Color(10,10,10));k=k+4;}
  pixels.setPixelColor(mnt, pixels.Color(0,0,0));
  pixels.show();
  
   


}




}

Solution: Present it quickly so no one has time to notice the hour hand. Or present it with a mirror.

Rhetorical: How does putting together what is basically a kit with a microcontroller and video step by step directions count towards a microprocessor class?

solution will not work.

No more rhetoric please.

Maybe you'll get a better grade when you explain how you built it incorrectly but then were able to fix the code to make it work anyway.

Grade is not important. I honestly do not have to turn clock in. I have spent a lot of time and money on this clock and i want it to work properly. Yes i did mess up, i understand that. But what i need is help fixing my mess up. If you are willing to help it would be appreciated. If more information is needed please tell me what i can do to make the problem more fixable.

Thank you

Brandon

I am not 100% sure but i think it is the RTC that is controlling the time. So I need to find a way to get the RTC to count backwards on the hour hand. I am not sure this is possible any advice would help.

I didn't look to deep but maybe try this.
Change this:

        if(data=='+')
          {
           hr++;
          }
        if(data=='-')
          {
           hr--;
          }

to this:

        if(data=='+')
          {
           hr--; // switch these 2
          }
        if(data=='-')
          {
           hr++; // switch these 2
          }
Adafruit_NeoPixel pixels = ...;

Adafruit_NeoPixel pixels2 = ...;
Adafruit_NeoPixel strip = ...;
Adafruit_NeoPixel strip2 = ..;

Are we supposed to guess which of these strips contains the hours? Give them useful names, not numbers.

If the hours is totally backwards, then maybe 11-hr will give you the correct LED number to use?

Regarding your post Hutkikz, Yes, i have added that into the code. It fixes the mode in the app. Before when you clicked + in the app to set time for the hour it would go down because i wired the LEDs wrong. After i changed code to that the app changes time properly but it does not help with the hour hand going backwards.

I am thinking that i need to somehow add a if statement that subtracts 2 from the hour every time it changes hour. It might glitch a little every hour change but atleast time would stay correct. That is the only solution i have come up with. I still do not know how i would do that and where i would need to add that into code but its a solution.

Regarding your post MorganS, i am not sure what you mean. Where would i put into code 11-hr.

Don't subtract 2 from the hour. That's definitely a two-steps-back solution.

Keep the internal representation of hour. 1-12 or 0-23, whatever you prefer. Just do a little subtraction when you display it on the 'backwards' strip to reverse the order.

Like when you display character '2' on the screen (or LCD or whatever) you're actually displaying character number 50 in the ASCII character table. You never convert 2 to 50 except at the very final point of display. That's what the print() function does for you. It would make mathematics very difficult.

Every time your sketch displays the hour like this:

pixels2.setPixelColor(hr, pixels2.Color(255,0,0));

change it to something like this:

pixels2.setPixelColor(12-(hr % 12), pixels2.Color(255,0,0));

There are a few similar lines you'll need to change. You'll probably need to reverse the change suggested in reply #8 to keep things consistent.

pixels2.setPixelColor(12-(hr % 12), pixels2.Color(255,0,0));

This code seemed to work
Thank you for your help.

Brandon

In the end it was this code that worked,

  pixels2.setPixelColor(11-(hr % 12)

When i used this code it would not display the 11 hour.

pixels2.setPixelColor(12-(hr % 12), pixels2.Color(255,0,0));

Problem Solved