📜 ⬆️ ⬇️

Dog collar

Introduction

So, I have a dog.
Brief summary:
Nickname: Squirrel
Color: White with red
Breed: West Siberian with someone else
Origin: Noble
Cost: 0p 0k

The dog was purchased at its own entrance for food and shelter. Was thrown out by some villains without food and water in a cardboard box without company logos of the breed and the address of the manufacturer. Well, it does not matter, we have dealt with a lower-quality product, and here such a red face, and completely free. We take!
I had to take the goods as is, NO-NAME. Most likely made in China. Warranty claims are also unclear to whom to bring, and they were - in a dog there were worms longer than itself. Fortunately, all this is in the past. The beast has grown up. She proved her loyalty and obedience, for which she was able to walk without a rope around her neck. Since this is not just a dog, but a real reverie dog, which is used to a full four-time walk without a leash (I’m not at all aggressive, but very curious and obedient), it took a kind of beacon to watch its adventures even in the dark, and not nervous where did she go. And to eat her is where - her favorite activity - to bring sticks to the owner, and to demand that he threw it. Well, to find, really her business. But this is not a simple dog, but a dog, whose folder is a programmer and a little bit of an electronics engineer. However, even a simple collar with DealExtreme attracts the eyes of others, especially children are happy. Isn't it worth it? But let's start from the beginning. Under the cut a lot of text!

Factory models
So, I ordered a collar with DX that glows in the dark. If you're curious, here it is .

Electronic unit in the housing

This is what his offal looks like when turned on.

The light guide is actually transparent. Made of some kind of flexible plastic or rubber, it has an oval cross section with a cutout for the LED and is fixed on top with heat shrink.

Can I recommend it for purchase? A moot point. Yes and no. Why yes? He works. Its light guide really shines, and there are 3 modes - constant, blinking and quickly blinking. It is powered by one CR2032 battery. Consumption about 20mah. Why I will not recommend it? Because the cunning Chinese saved a piece of light guide, and on my dog ​​it only lasts half the neck, since it turned out to be just opened to the full length. However, even this is enough for the wow-effect from other dog breeders, and just very impressionable citizens. Recently, collars have appeared much cheaper, and in different colors . Here I am waiting for this

Fresh addition. The collar came, very disappointed me. It is small, it is faulty, it is very badly made. I do not recommend.
I don’t presume to judge their sizes and exact characteristics, I don’t have one yet, but it will be soon, because the redhead for my project doesn’t fit - through the colored collar you cannot see colors except red. Ibey is also full of different modifications, it is searched for on request Dog collar. And despite having a suitable collar, I decided to go further!
')
So, the main idea was to make a collar on an RGB LED that would be shaded in different colors. In China, I have not found such, but I want to do something unusual, which no one has! Well, it's all the cooler than a simple red blinker! Now arduin-haters will come running, and they will say that all that Atmel microcontrollers can do is flash diodes. And they will be right - it turns out they do quite well, at least, the outputs are quite pulling the LED without the need to install transistors. Of course, I did not embed the arduin into the collar, and I never had it once. But with AtMega controllers dealt with. Therefore, I chose AtTiny13A. Why a? Because they have clever energy saving technologies! Let's figure it out!

Energy saving
Since the power from our batteries, the energy must somehow save. At least in the off state. We didn’t want to set the switch, so we have only one button to turn on, turn off and switch modes. As a result of Datasheet smoking, it turned out that there is a special power-down mode that will help us save extra battery energy when the collar does not need to shine to the envy of those around! Let's start with it. There is a special interrupt INT0, which allows our sleeping beauty AtTiny to wake up without the help of seven dwarfs and the handsome prince - you just need to hang a specially trained button on the right foot! So that's great! On the button, just reset all the colors that we need to display to black, reset the settings of the last selected mode, well, all sorts of suppressing bounce of buttons, turning off the diode at the moment of pressing, and of course, switching the mode - why else does the user need this single button!

ISR (INT0_vect) 
{
	OFF_LED();
	WAITBUTTON();
	mode++;
	if (mode>MAX_MODE) mode=0;
	want_new_color=1;
	need_delay=0;
	R_value=0;
	G_value=0;
	B_value=0;
	ON_LED();
}


! , . , ! - ? , , , . , .


- . BAM! - , . . BAM. - . 0 255. , . — 1, 128 , — 64 , - 32, . . - . ! , , . , OCR0A. :

ISR(TIM0_COMPA_vect)
{
	OCR0A>>=1;
	if (OCR0A==0) OCR0A=0x80;

	// 
	uint8_t leds=0xFF;

	//    
	if (R_value&OCR0A) leds^=LED_R;
	if (G_value&OCR0A) leds^=LED_G;
	if (B_value&OCR0A) leds^=LED_B;

	//!
	PORTB=leds;
}


, BAM (Bit angle modulation) , (PWM – Pulse Width Modulation), ! , 600 (4.8, 8), 8, 5 , , . 8, , , ! ? , ! , :
OCR0A>>=1;
if (OCR0A==8) OCR0A=0x80;

, . ? , power-down, BAM . , ASM-, -128. … (FOREVERALONE.JPG)

? . ( , ). — 256 + . , . .

uint8_t inc_light(uint8_t value) {

	if (value<50) value++;

	else if (value<128) value+=2;
	else if (value<253) value+=3;
	else value=255;
	return(value);
}



. main() , R, G, B. . , « ». Random() , TCNT0. , .

if (want_new_color) {
	new_color=color;
	while((color==new_color)|(new_color==0)) {
		new_color=((TCNT0^(TCNT0>>3)) & 0b00000111);
	}	
	color=new_color;
	want_new_color=0;
}


, , - , , . .

. — . . — .
. — « ». - . , . . — , , . AVR Studio 4.18 build 700, WinAVR-20100110. 992 , . . , HEX . , . , .


, . , .

4 . BTN GND . AtTiny13A, . 2 CR2032 (6V), LP2980 5V 50mA. , 15mA. , «» , . , 3.3V. 9.6 . 47, 10V, B. , , . , , . 12V , .

, .




, . , ( ). ? !


— . , , ? , 7V, 5.5V . - , . 65 . , , . fail: , , . . , . , , . , .



— . . , !

,

. , , , , home video. . 18+, .

2. , . , , .

Source: https://habr.com/ru/post/155427/


All Articles