0

12mm Coin Cell Breakout on Trinket M0
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

12mm Coin Cell Breakout on Trinket M0

by Virtuous70 on Sat Apr 20, 2019 2:44 pm

Hello,
I'm exploring the most compact way to light 3 LEDs. They will only be active for a few seconds at a time, and then not very often, so I'm hoping to do this with a small coin battery.
I'm new to what Adafruit offers, but I was thinking about a Trinket M0 with the LEDs attached, all switched on using Adafruit's tilt-ball switch. (Needs to operate with a tilt switch).
Is it a simple task to solder the 12mm coin cell breakout board (no switch) directly to the Trinket M0? I'm looking at the pins on each and not seeing a simple connection option like their JST-PH connector.
Or is there a better/smaller way?
Thanks

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: 12mm Coin Cell Breakout on Trinket M0

by adafruit_support_mike on Sun Apr 21, 2019 12:13 am

Virtuous70 wrote:Is it a simple task to solder the 12mm coin cell breakout board (no switch) directly to the Trinket M0?

Sure.. just connect the coin cell breakout's + and - pins to 3V and GND on the Trinket M0.

You might run into some problems if you want to use the tilt-ball sensor to control power to the Trinket M0. The ball switch connection is sensitive to bumping, and any interruption will force the Trinket M0 to reboot.

adafruit_support_mike
 
Posts: 59156
Joined: Thu Feb 11, 2010 2:51 pm

Re: 12mm Coin Cell Breakout on Trinket M0

by Virtuous70 on Sun Apr 21, 2019 12:51 am

Ah, okay. Thanks. Can I just connect the tilt switch to one of the input pins and have that activate the LEDs? Thanks for the warning about instability.

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: 12mm Coin Cell Breakout on Trinket M0

by Virtuous70 on Sun Apr 21, 2019 7:34 pm

As I said, I'm pretty inexperienced here... I tried assembling the code using blocks so I could see if it worked in the makecode simulator. Eventually, I got it to work when I click the input button, but when I release the button, I want all three LEDs to go off, and they just stay on.
Here's what I want: Upon button push (which will be the tilt-ball switch turning on) on pin 4, two LEDs (pins 1 and 2) should alternately blink, while a third LED (pin 3) should illuminate with low brightness).
I want all lights to keep doing their thing until I release the button (tilt the ball switch back), at which point I want all LEDs to go off.

Seems like a simple circuit, but I can't even make it work with blocks.
Please help me understand what I'm doing wrong.
Thanks
maker-screenshot.png
maker-screenshot.png (372.74 KiB) Viewed 120 times

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: 12mm Coin Cell Breakout on Trinket M0

by Virtuous70 on Mon Apr 22, 2019 11:44 pm

Made some progress after looking at the switch tutorial. Everything works the way it should, though I'd like to have the LED on A3 illuminate with only about 20% brightness, and I don't see how to do that if it is reading the switch. Also, not sure what that element is to the right of the third LED or why I need it.

maker-Rangefinder-LEDs (3).png
maker-Rangefinder-LEDs (3).png (60.8 KiB) Viewed 101 times


maker-screenshot (1).png
maker-screenshot (1).png (253.45 KiB) Viewed 101 times

Virtuous70
 
Posts: 22
Joined: Sat Nov 04, 2017 7:46 pm

Re: 12mm Coin Cell Breakout on Trinket M0

by adafruit_support_mike on Tue Apr 23, 2019 1:16 am

The Fritzing diagram shows a light-sensitive resistor. You didn't mention wanting that feature originally, so you can ignore it.

We control the brighness of LEDs using Pulse Width Modulation, or PWM. If you turn the LED on and off for equal amounts of time, it only emits light half the time, so the total light emission over time is only half as much. If you do that at 100Hz, the on/off pulses are too fast for the human eye to see, so the LED will just look dimmer.

PWM involves controlling the ratio of time-on to time-off, which is known as the signal's 'duty cycle'. If the LED is on 10% of the time and off 90% of the time, it's called a 10% duty cycle.

Many microcontroller pins can generate PWM signals. On the Trinket M0, pins 0, 2, 3, and 4 can do PWM. You control them from code with the analogWrite() function.

There's one more catch in controlling LED brightness though: the human eye responds to light logarithmically.. we see ratios of brighness better than we see absolute brightness. It gives us the power to see stars on a dark night and under the noonday sun.. a ratio of about 10 million to 1 in terms of the number of photons hitting our retinas. In practice, we see 'twice as many photons' as the same increase in brightness, no matter what the original light level was. And in fact, it's a change that's difficult to see.

To get what looks like a smooth change in brightness to the human eye, you'd need a series of PWM duty cycles that run 100%, 50%, 25%, 12%, 6%, 3%, and so on.

adafruit_support_mike
 
Posts: 59156
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.