Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino - tutorijali, pitanja, primjeri i projekti
Malopre sam greskom postavio pitanje u drugoj temi,izvinjavam se,ko breise neka brise prethonu poruku.

Ajde da ponovo pitam nesto.Probao sam da na tasterima napravim da menjam duty na arduino,to sam vec pravio sa potenciometrom koristeci ADC i radi najnormalnije a sad na isti nacin samo sto bi tasteri menjali vrednost OCR1A nece da radi,idnosno ima fiksni duty koji se nemenja na pritisak tastera a posle par minuta duty se smanji i ostane samo linija na osciloskopu.Evo kako sam probao:


//MOD 8 PHASE AND FREQENCY CORRECT PWM
int taster1 = 2;
int taster2 = 3;
int impuls;


void setup(){
DDRB |= (1<<PB1)|(1<<PB2);
TCCR1A = 0;
TCCR1A = 0;
TCCR1A = (1<<COM1A1) + (1<<COM1B1);
TCCR1B = (1<<WGM13) + (1<<CS10);
impuls = 500; //pocetna vrednost
ICR1 = 2000; //perioda
OCR1A = impuls;
pinMode(taster1,INPUT);
pinMode(taster2,INPUT);

}

void loop() {

PORTB |= (1<<PB1)|(1<<PB2);
OCR1A = impuls;


if(digitalRead(taster1)==LOW){

ICR1 = 2000;
OCR1A = impuls;
impuls=impuls+1;

delay(300);
if(impuls>1000){
impuls=1000;
PORTB |= (1<<PB1)|(1<<PB2);
}
}

if(digitalRead(taster2)==LOW){

ICR1 = 2000;
OCR1A = impuls;
impuls=impuls-1;

delay(300);
if(impuls<1){
impuls=1;
PORTB |= (1<<PB1)|(1<<PB2);
}
}
}
Reply


Messages In This Thread
RE: Arduino - tutorijali, pitanja, primjeri i projekti - by MILANNN - 10-03-2022, 06:52 PM

Forum Jump:


Users browsing this thread: 25 Guest(s)