Moon Phase Clock modifications

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bzflaglegomaniac
 
Posts: 10
Joined: Fri Oct 18, 2019 7:44 pm

Moon Phase Clock modifications

Post by bzflaglegomaniac »

I love the Moon phase clock. I'd like to make two modifications, however I've never programmed in Python, only the Arduino (recently), and assembly language way back in the last century. Frankly, I'm feeling overwhelmed.

The two changes I want to make are to:
1) change the date, which is currently all monochrome, to having the "/" in a different colour so it doesn't blend in with the "26". In other words, currently <white>10<white>/<white>26 to something like <white>10<orange>/<white>26.

Having never seen Python, I was expecting to see a statement (Line 221) like:
CursorColour(white);Print(month+"/"+day);
where I was expecting to be able to replace it with:
CursorColour(white);Print(month);CursorColour(orange);Print("/");CursorColour(white);Print(day);

Instead, I have absolutely no idea what to do with it.

The second thing I'd like to do is dim the display in response to the ambient light in the room. Obviously this would require an external light sensor, but that not with standing, is there a way to to go pixel-by-pixel and read the current value of the colour for that pixel? Then, if the room is dark, write a dimmer version of that pixel?

When I saw the pictures of the project I presumed this was how the shadow of the Moon was being displayed - the shadowed area being darkened where appropriate on an otherwise fully lit Moon, but instead they use 100 different pictures which makes my skin crawl. Keeping in mind I learned coding on microcontrollers with 64 bytes (just bytes) of RAM.

I ask this because seeing the Moon made me think of one of those Geochron Earth clocks that shows which parts of the Earth are in daylight which might make a good, if very low-resolution, project.
Attachments
Geochron Map.jpg
Geochron Map.jpg (174.25 KiB) Viewed 546 times

User avatar
sembazuru
 
Posts: 141
Joined: Sat Mar 30, 2013 2:50 am

Re: Moon Phase Clock modifications

Post by sembazuru »

The second thing I'd like to do is dim the display in response to the ambient light in the room. Obviously this would require an external light sensor, but that not with standing, is there a way to to go pixel-by-pixel and read the current value of the colour for that pixel? Then, if the room is dark, write a dimmer version of that pixel?
I'd be interested in this as well. I did something similar (in Arduino) with a 7-segment clock using the backpack. The 7-segment backpack library has a way to adjust the full display brightness, but I haven't looked to see if the MatrixPortal library has a similar function/method. Back then I used the GA1A12S202 breakout which is now discontinued. Now I'd probably try to use the VEML7700 breakout and wire it to the STEMMA QT connector on the Matrix Portal board. Also, unfortunately, all the inexpensive (sub $1) STEMMA QT cables seem to be out of stock...

User avatar
bzflaglegomaniac
 
Posts: 10
Joined: Fri Oct 18, 2019 7:44 pm

Re: Moon Phase Clock modifications

Post by bzflaglegomaniac »

Actually, I was just going to use a good old fashioned photoresistor {https://www.adafruit.com/product/161) - I've been using them since the 70's for this type of job. Just connect it between Ax and ground. Be sure to use a pull-up resistor, which is probably programmable, and the brighter the room, the lower the measured voltage on Ax. You'll need to experiment to see what analog values you measure at Ax for a fully-lit room and full darkness. Take that measured value and decide on the number of dimming steps you want (say, 4) then go through each pixel and divide each of the R G and B values by the number current dimming step (ie. 1 becomes full brightness; 2, 3 and 4 become half, third and quarter - that should be good enough). Just a word of caution - the steps need to be larger than can be accounted for by the brightness of the display. That is to say, if you start in a dark room, but 1/4 dimness is bright enough to illuminate the room above the step 3 threshold then the display will never stay at minimum brightness. Using any kind of ambient light sensor to control a light source always involves some consideration for how much of the controlled sources light it's own sensor can "see". That was harder to do in the old analog days but is much easier to do with a computer.

User avatar
Jazzbert
 
Posts: 1
Joined: Thu Dec 01, 2016 5:31 pm

Re: Moon Phase Clock modifications

Post by Jazzbert »

Regarding your first goal, it looks like the provided code uses adafruit_display_text.label to create the text on the screen. This does not support multi-colored text. You'd essentially have to create 3 separate labels if you want to change the color of just the slash. I'm not sure if there are other ways to easily update this with a different class.

You could easily add a space in the text in the code when the date is updated (around line 421). I'm changing it to different format anyway as I prefer D MMM format. Taking a little more work, but I don't think it's crazy hard.

-Jazz

User avatar
AfterTen
 
Posts: 6
Joined: Thu Oct 08, 2020 12:17 am

Re: Moon Phase Clock modifications

Post by AfterTen »

Attached is the code that separates the date into 3 fields. So you can assign a different color to each.
Line 224 is where you assign a color, in HEX for RGB, to the slash. I've set it to the orange - 0xC04000
Line 222 is for the month - actually the first field. Later in the code you could set it to the Day if you'd like.
Line 226 is for the day.

Line 429,430 & 431 is where the actual date data is placed into these fields.

Let me know if you have any questions.

(edit: I deleted my original post to post this with new code that fixes a cosmetic bug in the first version.)
Attachments
code.py
(19.17 KiB) Downloaded 20 times

User avatar
powershift
 
Posts: 36
Joined: Sat Sep 13, 2014 9:50 am

Re: Moon Phase Clock modifications

Post by powershift »

Hi, AfterTen,

I tried your code and got a "Memory Allocation" error on line 433 - it seems that MatrixPortal run out of memory. I tried to delete the splash screen and it does not seem to help. I am pretty new to Python (most on C and Arduino code) so I am kind of not sure what is the best way to debug this?

Thanks,

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”