Graphical LCD ClockCS109 Programming ProjectsSpirit levelDay and Night

Day and Night

In this project we want to make some fun use of the light sensor in the phone.

Note that not every phone makes it's light sensor available to apps. You can check this with the light.kt mini-app.

The idea is to show an image that changes depending on the current light sensor input. In a bright environment, is shows a scene in bright daylight. In a dark environment, it shows a night time scene.

Here are two images from a simple implementation:

Daytime scene Night scene

While you change the illumination from bright to dark (you can test this nicely on the emulator using the slider in the light sensor window), the color of the sky and the land must change continuously. The sun sets when it gets darker, finally the moon rises—and vice versa, when it gets bright again.

You can improve this simple version in many ways: The color of the sun changes when it sets (from yellow to orange to deep red). Place something in the empty space on the right side, such as a house, a tree, or an animal. The animal could walk around during bright light, and go to sleep in the night.

To get you started, here are the colors I used for day and night scenes (and I'm interpolating in between):

    val sky1 = Color(152, 255, 255)
    val sky0 = Color(7, 22, 124)
    val grass1 = Color(26, 214, 13)
    val grass0 = Color(11, 88, 5)
    val sun1 = Color(251, 253, 78)
    val moon1 = Color(230, 225, 202)
Graphical LCD ClockCS109 Programming ProjectsSpirit levelDay and Night