# Tufty 2040 \> code \> Tufty 2350

**URL:** <https://forums.pimoroni.com/t/tufty-2040-code-tufty-2350/28725>\
**Category:** Support\
**Created:** [February 28, 2026, 2:35pm UTC](https://forums.pimoroni.com/t/tufty-2040-code-tufty-2350/28725 "2026-02-28T14:35:57Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![alphanumeric](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/alphanumeric/32/2729_2.png) [@alphanumeric](https://forums.pimoroni.com/u/alphanumeric)\
**Post date:** [March 6, 2026, 1:57pm UTC](https://forums.pimoroni.com/t/tufty-2040-code-tufty-2350/28725/25 "2026-03-06T13:57:46Z")

</div>

I’ve found the code I need for the battery state. =)

```auto
badge.battery_level()
#Returns an int representing the battery level as a percentage from 0 to 100.
print (badge.battery_level())

badge.battery_voltage()
#Returns a float representing the current battery voltage.
print (badge.battery_voltage())

badge.usb_connected()
#Returns a boolean reflecting whether the USB cable is currently connected.
print(badge.usb_connected())

badge.is_charging()
#Returns a boolean reflecting whether the battery is currently charging.
print(badge.is_charging())

```

It’s plugged in and fully charged.

```auto
MPY: soft reboot
100
4.214976
True
False

```

I’ve also found the code to read the built in light sensor.

```auto
badge.light_level()
#Returns the level detected by the light sensor as a raw u16 value.
print (badge.light_level())

```

```auto
MPY: soft reboot
1936

```

I’ll have to go dig out my flashlight and play around with what values I get. Been there and done that with my Tufty 2040.

Something doesn’t quit seem right with the case lights code though?  
Or I’m doing something wrong?

> [@Tufty 2350 Case Lights](https://forums.pimoroni.com/t/tufty-2350-case-lights/28750):
>
> In the API documents i have found the following Lighting Badgeware is fitted with four onboard white LEDs on the back of the board. These can be used as indicators, decoration or anything else you can think of. Tufty also has a front-mounted light sensor which caselights() Gets and sets the brightness value for the rear lighting on the badge. Usage .caselights() - Returns the current level of the rear LEDs as a tuple. .caselights(level) - level - Brightness to set on all rear LEDs (0-255) .ca…

@BillyTPilgrim You don’t happen to know where the code is stored for the battery widget that’s displayed on the Badge OS… App select screen is?

**EDIT:** It looks like its in /system/apps/menu/ui.py

---

_[View the full topic](https://forums.pimoroni.com/t/tufty-2040-code-tufty-2350/28725)._
