toblum / esp_p10_tetris_clock

A tetris clock based on a 16x32 RGB matrix and a ESP8266
MIT License
49 stars 17 forks source link

12-hour format? #2

Closed BCChad closed 6 years ago

BCChad commented 6 years ago

Hi - I was sure I'd find this option already existed for the Tetris clock but can't find it after digging through several libraries. I see in TimeLib where a 12-hour format call "exists" but I think it has to be changed I ntp_time?

Please advise. Thanks. This is a great project !!!! Bruce

toblum commented 6 years ago

Hi @BCChad, I'll have to check that. One simple workarouns could be to get the hours as number, substract 12, if hours > 12 here: https://github.com/toblum/esp_p10_tetris_clock/blob/c89c0425415988c8caac4d6067a0e1ad050c0bfc/src/ntp_time.h#L43

Regards Tobias

BCChad commented 6 years ago

Hi Tobias, Good idea - I'm working on it; gets a little messy. I can extract the hour substring and convert it to integer to do the math. But when the hour is only one digit, like 7 am, on converting it back to string I need it to have a leading zero "07." I think there's a formatting command that will do that for me - if you have this readilly available in your near-term memory, I would appreciate it! I'll insert my code in the next reply after I fix some issues...

BCChad commented 6 years ago

Tobias - I finished this challenge - creating a function "fixTime" and playing with it a few times to compact it as much as possible. I learned a lot by doing this! Very happy if you or someone else offers insights for better code construction. (I wanted to paste the code here but the "Insert Code" feature does not put the code in as your example shows. When I figure that out I'll paste it here.)

BCChad commented 6 years ago

In my ignorance I pressed the "FORK" button, which immediately adds a fork to your code. I apologize, please delete it.

toblum commented 6 years ago

Hi @BCChad, forking doesn't do anything with my code. Think of a fork as your personal copy you can work on. You can safely delete it, or use it to do your own development. If you want you can later share your changes with the forked project as a pull request, Pasting code is easy, just enclose it into the backticks ` that are inserted with the button. Regards Tobias

BCChad commented 6 years ago

Thanks - I drafted that with the "back ticks" and the formatting did not look right to me when "previewing", but I'll do as you say.

On Sat, May 26, 2018 at 3:00 PM, Tobias Blum notifications@github.com wrote:

Hi @BCChad https://github.com/BCChad, forking doesn't do anything with my code. Think of a fork as your personal copy you can work on. You can safely delete it, or use it to do your own development. If you want you can later share your changes with the forked project as a pull request, Pasting code is easy, just enclose it into the backticks ` that are inserted with the button. Regards Tobias

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-392281663, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuHZxD3vaXv7WJzgfjpSLXUK029K4ks5t2aZagaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

BCChad commented 6 years ago

Here is the function I created to convert to 12-hour. I didn't deal with putting a dot out there for AM vs. PM but suppose that could be added. Had fun doing this - learned a few new tricks. Tried to make it as compact as I knew how - any suggestions are gladly accepted!

String fixTime(String cur_Time) {      // Patch to change 24-hr to 12-hr, called if bool flag set
  // (function by BCChad  05/25/2018)
  String hours = cur_Time.substring(0, 2);  // get hours substr
  cur_Time.remove(0, 2);           // remove it
  int hoursint = hours.toInt();   // change hours substr to integer
  hoursint = hoursint % 12;   // peel off values > 12
  if (hoursint == 0) hoursint = 12;  // 12-hr clock doesn't have "00"
  hours = String(hoursint);  // Convert integer back to string
  if (hoursint < 10) hours = "0" + hours; //  add a leading zero if needed
  String twelveTime;
  return twelveTime = hours + cur_Time;   // Put time string back together
}

Here's the call from Tobias' original code, inserted in line 91 of his:

    String str_current_time = getTimeAsString();  // call to lib Ntp_time
    if (twelvehr) {  // "fix" current time from 24 to 12 format; global flag set above
      str_current_time = fixTime(str_current_time);  // declared new function below
    }

    // Time has changed
...etc.

I created a global bool flag to indicate preference for 12-hour, inserted as line 20 of his file: bool twelvehr = true; // Set to false for 24-hour clock

toblum commented 6 years ago

Hi @BCChad,

thank you for the code example. I have put this on the enhancements list (https://github.com/toblum/esp_p10_tetris_clock/blob/master/README.md).

Best regards Tobias

BCChad commented 6 years ago

OK - by the way I was not happy with how the brackets formatted the code and assume I have done something wrong. I formatted the code in the Arduino IDE and did a EDIT\COPY FOR FORUM to paste it in the brackets. When I did that, it looked ok initially but after saving the post, the nice formatting disappeared. It certainly does not look like the example line you had pasted in. If you have a better tip for me, I'm all ears. I looked around the tutorials but so far haven't found the appropriate instructions.

On Sat, Jun 2, 2018 at 4:49 PM, Tobias Blum notifications@github.com wrote:

Closed #2 https://github.com/toblum/esp_p10_tetris_clock/issues/2.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#event-1659765359, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuBTV-YTkuD4I4nkUBB0A8w-6YETiks5t4vpzgaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

toblum commented 6 years ago

Hi @BCChad,

just use the "Insert code" button in the toolbar. This puts the code in three backticks. That works OK. You could also add the language for highlighting in the opening marking e.g. ```c Have a look here: https://guides.github.com/features/mastering-markdown/

It just tried it out with your post.

Best regards Tobias

BCChad commented 6 years ago

Thanks Tobias, I appreciate the helpful support.

BCChad commented 6 years ago

Hello Tobias, Please forgive the question, but perhaps you can clarify.. I ordered the P10 display as listed but when it arrived today it looks different than the two examples in the PxMatrix instructions (see attached photo). I am attempting to sort through those two examples to find the correct information to hook up my ESP8266.

I believe the connection block on the left marked "IN" is used, but there are some additional connections to the "OUT" connector... Also, per the photo you provide - the heaver VCC / GND red & black cable is not used?

Any help is greatly appreciated. Thank you. In the meantime I will attempt to connect this.

Bruce

On Sat, Jun 2, 2018 at 4:49 PM, Tobias Blum notifications@github.com wrote:

Hi @BCChad https://github.com/BCChad,

thank you for the code example. I have put this on the enhancements list ( https://github.com/toblum/esp_p10_tetris_clock/blob/master/README.md).

Best regards Tobias

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-394116179, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuBTV-YTkuD4I4nkUBB0A8w-6YETiks5t4vpzgaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

toblum commented 6 years ago

Hi @BCChad,

I' afraid but I think I can't help (but I may try) here as I also just used @2doms library. I would suggest that you ask the question there: https://github.com/2dom/PxMatrix/issues I'm quite sure that @2dom can help. I also saw that you attached your image in your e-mail reply. That doesn't work in Github. You have to upload yout image somewhere (e.g. imgur, ...) and post the link to that image.

Best regards Tobias

BCChad commented 6 years ago

Thank you - can you at least confirm - even though the photo shows no connection to VCC and GND - I assume I have to provide power to VCC in order to power the LED matrix, correct?

On Wed, Jun 6, 2018 at 4:23 PM, Tobias Blum notifications@github.com wrote:

Hi @BCChad https://github.com/BCChad,

I' afraid but I think I can't help (but I may try) here as I also just used @2doms library. I would suggest that you ask the question there: https://github.com/2dom/PxMatrix/issues I'm quite sure that @2dom https://github.com/2dom can help. I also saw that you attached your image in your e-mail reply. That doesn't work in Github. You have to upload yout image somewhere (e.g. imgur, ...) and post the link to that image.

Best regards Tobias

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-395201352, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuESh5CIznCiFJ7hBEF5RhlKqU1hJks5t6Do5gaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

toblum commented 6 years ago

Hi @BCChad,

unfortunately there is no photo attached here. You will have to provide it like I wrote in my last reply.

Regards Tobias

toblum commented 6 years ago

But yes, you need to provide power to the matrix, independent from the data connections. If it’s not too big and your power supply for the esp is beefy enough, you can take the power directly from the esp pins.

BCChad commented 6 years ago

I made one bug fix to my "fixTime" function - I incorrectly used the << operator when a simple < was needed (when comparing hoursint to 10).

BCChad commented 6 years ago

Tobias - you have been very helpful, thank you. Just to update you - I have succeeded connecting the display and your code executes well. My only issue to resolve is that I'm getting a few artifacts on the display:

On Thu, Jun 7, 2018 at 6:22 AM, Tobias Blum notifications@github.com wrote:

But yes, you need to provide power to the matrix, independent from the data connections. If it’s not too big and your power supply for the esp is beefy enough, you can take the power directly from the esp pins.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-395371306, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuGRaUcGBuNMfYtxDadCEpDWlaWjzks5t6P8AgaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

BCChad commented 6 years ago

Problems are resolved - one error in wiring has been corrected.

I see someone may have already suggested an enhancement - what if periodically the display was interrupted with a report of local temperature/humidity/weather alert?

toblum commented 6 years ago

Hi @BCChad,

great that you make it work. I setup a new 32x32 matrix with a ESP32 a few days ago, because I want to try this out a bit. It took me three attempts to wire everything correctly. Errors happen very easy. :-) Updating weather could freeze the clock animation for a short time. So I was looking into the ESP32 with it's two cores to accomplish that, But I'm still at the beginning.Never really worked with the ESP32 before.

Regards Tobias

BCChad commented 6 years ago

Hi Tobias, Just to let you know that I'm working on my "fork," if you happen to have access to that activity. I have created a simple enhancement at the request of my wife - since the LED panel is very bright, she wants it to shut off between 2200 and 0600 hours. I have succeeded at writing a simple routine for that and will add it to my fork (assuming I figure that system out).

As a point of discussion - the technique I used was to "detach" the two tickers in your code during that time, so the LED matrix goes blank. Later (at 0600) I "attach" the two tickers and it resumes. I was looking for for a simpler "display.noDisplay()" or "display.end()" as the more direct way to accomplish this, but PxMatrix doesn't provide such a function. If you have any suggestions, I am eager to learn from you.

On Sun, Jun 10, 2018 at 12:32 PM Tobias Blum notifications@github.com wrote:

Hi @BCChad https://github.com/BCChad,

great that you make it work. I setup a new 32x32 matrix with a ESP32 a few days ago, because I want to try this out a bit. It took me three attempts to wire everything correctly. Errors happen very easy. :-) Updating weather could freeze the clock animation for a short time. So I was looking into the ESP32 with it's two cores to accomplish that, But I'm still at the beginning.Never really worked with the ESP32 before.

Regards Tobias

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-396062476, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuCiJETLa1YIv8EVpayfBCNMurwLrks5t7UoogaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

toblum commented 5 years ago

Hi @BCChad,

I must have missed your message. Great that you've found a use for the library. I think that detaching the tickers is a quite elegant way to accomplish to do what you wanted to achieve as there is no built in possibility.

Best regards Tobias

BCChad commented 5 years ago

Tobias, I have just learned that I bought the wrong LED Matrix (!). The one you specified from Adafruit is 3.8 by 7.6 inches. The one I purchased (in haste) online is 6 by 12 inches. I bought a 16 x 32 LED matrix but wasn't aware there were different sizes. Foolish me. I learned the mistake after paying for the 3D printing.

My clock is much larger than yours ; it lights up the whole room! Lesson learned! Bruce

On Tue, Jun 19, 2018, 4:14 PM Bruce Chadbourne bruce.chadbourne@gmail.com wrote:

Hi Tobias, Just to let you know that I'm working on my "fork," if you happen to have access to that activity. I have created a simple enhancement at the request of my wife - since the LED panel is very bright, she wants it to shut off between 2200 and 0600 hours. I have succeeded at writing a simple routine for that and will add it to my fork (assuming I figure that system out).

As a point of discussion - the technique I used was to "detach" the two tickers in your code during that time, so the LED matrix goes blank. Later (at 0600) I "attach" the two tickers and it resumes. I was looking for for a simpler "display.noDisplay()" or "display.end()" as the more direct way to accomplish this, but PxMatrix doesn't provide such a function. If you have any suggestions, I am eager to learn from you.

On Sun, Jun 10, 2018 at 12:32 PM Tobias Blum notifications@github.com wrote:

Hi @BCChad https://github.com/BCChad,

great that you make it work. I setup a new 32x32 matrix with a ESP32 a few days ago, because I want to try this out a bit. It took me three attempts to wire everything correctly. Errors happen very easy. :-) Updating weather could freeze the clock animation for a short time. So I was looking into the ESP32 with it's two cores to accomplish that, But I'm still at the beginning.Never really worked with the ESP32 before.

Regards Tobias

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-396062476, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuCiJETLa1YIv8EVpayfBCNMurwLrks5t7UoogaJpZM4UJdIO .

-- Bruce Chadbourne 1034 W Beagle Run Loop Hernando, FL 34442

2dom commented 5 years ago

v1.3 of pxmatrix now includes global brightness control....

BCChad commented 5 years ago

Thank you! I have started experimenting with brightness of the clock. I believe it defaults to max (255), and I'm finding 8 to 16 a comfortable improvement. Still playing...

On Fri, Oct 12, 2018 at 1:06 AM Dominic Buchstaller < notifications@github.com> wrote:

v1.3 now includes global brightness control....

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/toblum/esp_p10_tetris_clock/issues/2#issuecomment-429205494, or mute the thread https://github.com/notifications/unsubscribe-auth/AltOuB_95xVROSpmBgq1nyw7qZeMd8pMks5ukCNMgaJpZM4UJdIO .

-- Bruce Chadbourne 306 Fern Circle Lebanon PA 17042