Cov txheej txheem:

Hloov LED Xim Siv POT thiab ATTINY85: 3 Cov Kauj Ruam
Hloov LED Xim Siv POT thiab ATTINY85: 3 Cov Kauj Ruam

Video: Hloov LED Xim Siv POT thiab ATTINY85: 3 Cov Kauj Ruam

Video: Hloov LED Xim Siv POT thiab ATTINY85: 3 Cov Kauj Ruam
Video: Tik Tok || Tseem Nco Koj Thiab Kuv P15 2024, Kaum ib hlis
Anonim
Hloov LED Xim Siv POT thiab ATTINY85
Hloov LED Xim Siv POT thiab ATTINY85
Hloov LED Xim Siv POT thiab ATTINY85
Hloov LED Xim Siv POT thiab ATTINY85
Hloov LED Xim Siv POT thiab ATTINY85
Hloov LED Xim Siv POT thiab ATTINY85

Hauv qhov haujlwm no peb siv lub zog ntsuas (POT) los hloov cov xim hauv LED siv ATTINY85.

Qee cov ntsiab lus -

Lub tshuab hluav taws xob yog lub cuab yeej nrog cov ntsia hlau me me / tig lub tshuab uas thaum tig tawm cov hluav taws xob sib txawv sib txawv. Koj tuaj yeem pom los ntawm cov duab piav qhia saum toj no uas POT muaj 3 tus pin, uas yog, +, -, thiab tso tawm. Lub POT tau siv los ntawm kev txuas cov + thiab - pins rau vcc thiab hauv av feem ntawm lub hwj chim. Raws li POT ntsia hlau tig, cov zis tsis kam hloov pauv thiab ua rau LED poob qis lossis nce ntxiv.. Hauv lwm lo lus, nws yog qhov sib txawv resistor. Lawv tau siv nyob rau hauv xws li cov teeb pom kev hauv tsev dimmers.

LED - Qhov no yog lub teeb me me uas pom thaum hluav taws xob hla txawm hais tias nws. Hauv qhov no, peb yuav siv ntau lub xim LED uas muaj 3 tus pin, ib qho hauv av (nruab nrab) thiab ob tus pin uas pom ntsuab thiab liab raws li thaum tshwm sim.

ATTINY85-qhov no yog tus nqi qis me me uas koj tuaj yeem ua haujlwm zoo li Arduino.

Txheej txheem cej luam - Cov txiaj ntsig los ntawm POT txuas nrog ATTINY85. Raws li POT ntsia hlau tig, qhov sib txawv tsis kam tawm yog ua tus lej nruab nrab ntawm 0 thiab 255. ATTINY tuaj yeem ntsuas qhov no thiab ua qhov sib txawv raws li tus nqi ntawm POT tsis kam. Hauv qhov no, peb tau npaj nws kom txuas rau LED raws li hauv qab no.

Yog tias tus lej ntau dua 170 hloov lub LED rau GREEN.

Yog tias tus lej tsawg dua 170 tab sis ntau dua 85 hloov LED rau RED.

yog tias tus lej tsawg dua 85 hloov ntawm LED GREEN THIAB RED uas ua rau ORANGE.

BOM

1 x 3 pin LED1 x ATTINY 85

1 x POT (B100K)

1 x breadboard thiab cables

1 fais fab mov.

Kauj ruam 1: Programming ATTINY85

Hais txog kev ua haujlwm ATTINY85, thov xa mus rau kuv cov lus qhia yav dhau los-https://www.instructables.com/id/15-Dollar-Attiny8…

Cov cai yog qhia hauv qab no. Qee cov ntsiab lus yuav tsum nco ntsoov yog ob qho ATTINY pins, PB3, tus pin lub cev 2, PB2, tus pin lub cev 7 tau txuas nrog, hauv hom digital, mus rau LED kom hloov xim. ATTINY tus pin PB4, tus pin lub cev 3, txuas nrog POT hauv hom sib piv, uas txhais tau tias nws tuaj yeem nyeem qhov tseem ceeb ntawm 0 thiab 254. Kuv tau kho tus lej uas kuv pom hauv internet yog li kuv lees paub tias ua haujlwm. -

void initADC () {// *** // *** Pinout ATtiny25/45/85: // *** PDIP/SOIC/TSSOP // *** ============= ====================================================================== ============================== // *** // *** (PCINT5/RESET/ADC0/dW) PB5 [1]* [8] VCC // *** (PCINT3/XTAL1/CLKI/OC1B/ADC3) PB3 [2] [7] PB2 (SCK/USCK/SCL/ADC1/T0/INT0/PCINT2) //* ** (PCINT4/XTAL2/CLKO/OC1B/ADC2) PB4 [3] [6] PB1 (MISO/DO/AIN1/OC0B/OC1A/PCINT1) // *** GND [4] [5] PB0 (MOSI/ DI/SDA/AIN0/OC0A/OC1A/AREF/PCINT0) // *** // pb4 - cov tswv yim rau POT // pb3 coj tus pin 1 // pb2 coj tus pin 3 // ATTINY 85 zaus teeb tsa sab hauv 8 MHz/* txoj haujlwm no pib ADC

ADC Prescaler Sau Ntawv:

ADC Prescaler yuav tsum tau teeb tsa kom ADC cov tswv yim zaus nyob nruab nrab ntawm 50 - 200kHz.

Yog xav paub ntxiv, saib cov ntawv 17.5 "ADC Prescaler Selections" hauv tshooj 17.13.2 "ADCSRA - ADC Tswj thiab xwm txheej sau npe A" (nplooj ntawv 140 thiab 141 ntawm qhov ua tiav ATtiny25/45/85 cov ntawv, Rev. 2586M – AVR – 07/ 10)

Siv prescaler qhov tseem ceeb rau ntau lub moos nrawm

Clock Muaj prescaler qhov tseem ceeb --------------------------------------- 1 MHz 8 (125kHz), 16 (62.5kHz) 4 MHz 32 (125kHz), 64 (62.5kHz) 8 MHz 64 (125kHz), 128 (62.5kHz) 16 MHz 128 (125kHz)

Hauv qab piv txwv teeb tsa prescaler rau 128 rau mcu khiav ntawm 8MHz

(txheeb xyuas cov ntaub ntawv rau qhov tsim nyog me ntsis qhov tseem ceeb los teeb tsa prescaler) */

// 8-ntsis kev daws teeb meem

// teeb tsa ADLAR rau 1 kom ua rau tshwm sim Sab laug-ua haujlwm (tsuas yog cov khoom ADC9.. ADC2 muaj) // tom qab ntawd, tsuas yog nyeem ADCH txaus rau 8-ntsis txiaj ntsig (256 qhov txiaj ntsig) DDRB | = (1 << PB3); // Tus pin tau teeb tsa ua qhov tso tawm. DDRB | = (1 << PB2); // Tus pin tau teeb tsa ua qhov tso tawm. ADMUX = (1 << ADLAR) | // sab laug ua haujlwm tshwm sim (0 << REFS1) | // Teeb tsa ref. voltage rau VCC, ntsis 1 (0 << REFS0) | // Teeb tsa ref. voltage rau VCC, ntsis 0 (0 << MUX3) | // siv ADC2 rau cov tswv yim (PB4), MUX ntsis 3 (0 << MUX2) | // siv ADC2 rau cov tswv yim (PB4), MUX ntsis 2 (1 << MUX1) | // siv ADC2 rau cov tswv yim (PB4), MUX ntsis 1 (0 << MUX0); // siv ADC2 rau cov tswv yim (PB4), MUX ntsis 0

ADCSRA =

(1 << ADEN) | // Pab kom ADC (1 << ADPS2) | // teeb tsa prescaler rau 64, ntsis 2 (1 << ADPS1) | // teeb tsa prescaler rau 64, ntsis 1 (0 << ADPS0); // teem prescaler rau 64, ntsis 0}

int main (tsis muaj dab tsi)

{initADC ();

thaum (1)

{

ADCSRA | = (1 << ADSC); // pib ntsuas ADC thaum (ADCSRA & (1 << ADSC)); // tos kom hloov pauv tiav

yog tias (ADCH> 170)

{PORTB | = (1 << PB3); // Pin teeb rau HIGH. PORTB | = (1 << PB2); // Pin teeb rau HIGH. } lwm yog (ADCH 85) {PORTB | = (1 << PB3); // Pin teeb rau HIGH. PORTB & = ~ (1 << PB2); // Pin teeb rau LOW

lwm yam {

PORTB | = (1 << PB2); // Pin teeb rau HIGH. PORTB & = ~ (1 << PB3); // Pin teeb rau LOW

}

}

rov 0;

}

Kauj ruam 2: Circuit Court

Circuit Court
Circuit Court

ATTINY tus pin

PB3, tus pin lub cev 2 - txuas nrog tus pin LED 1

PB4, tus pin lub cev 3, txuas nrog tus pin nruab nrab POT

GND, lub cev tus pin 4, txuas nrog txoj kev tsheb ciav hlau tsis zoo - lub zog siv

PB2, tus pin lub cev 7 - txuas nrog tus pin LED 3

VCC, tus pin lub cev 8, txuas nrog txoj kev tsheb nqaj hlau zoo - lub zog siv

POT

pos thiab neg pin txuas nrog rau txoj kab sib txuas - lub zog siv hluav taws xob.

LED

nruab nrab tus pin txuas nrog txoj kev tsheb ciav hlau tsis zoo - lub hwj chim

Kuv sim siv 3 thiab 3.3 volt fais fab mov thiab ob qho tib si ua haujlwm.

Kauj Ruam 3: Xaus

Xaus
Xaus

Lub peev xwm ntawm ATTINY85 txav mus los ntawm kev sib piv thiab hom digital yog qhov muaj zog heev thiab tuaj yeem siv rau hauv ntau qhov kev thov sib txawv, piv txwv li. tsav tsheb sib txawv nrawm thiab tsim cov ntawv sau nkauj. Kuv yuav tshawb qhov no hauv cov lus qhia yav tom ntej. Kuv vam tias koj tau pom qhov no muaj txiaj ntsig.

Pom zoo: