\$\begingroup\$
\$\endgroup\$
4
I have this code to blink an array (8-led) of led one after one:
#include <avr/io.h>
#include <avr/delay.h>
#define dela 500
int main (void)
{
DDRC = 0xFF;
for(int i=0; ; i++,i%=8)
{
PORTC |=(1<<i);
delay_ms(dela);
PORTC &= ~(1 << i);
delay_ms(dela);
}
}
I want to light up those led partially, like dimmed version of this, something like PWM
Now my question is how can I do that, how can I write analog output ?
Micro-controller : ATmega8A - PDIP
Maifee Ul AsadMaifee Ul Asad
asked Sep 28, 2019 at 14:06
1 Answer 1
\$\begingroup\$
\$\endgroup\$
6
Modulate the LED "on" time.
Something like this.
for(int i=0; ; i++,i%=8)
{
for(int k=0; k<26; k++)
{
PORTC |=(1<<i);
delay_ms(10);
PORTC &= ~(1 << i);
delay_ms(10);
}
delay_ms(dela);
}
-
\$\begingroup\$ I couldn't find any usage of
k
, What i want is like instead of outputtrue
offalse
, setting or resetting,0 volt or 5 volt. I want to write an analog output. \$\endgroup\$Maifee Ul Asad– Maifee Ul Asad2019年09月28日 16:39:00 +00:00Commented Sep 28, 2019 at 16:39 -
\$\begingroup\$ what does this mean? ...
I couldn't find any usage of k
\$\endgroup\$jsotola– jsotola2019年09月28日 19:01:55 +00:00Commented Sep 28, 2019 at 19:01 -
\$\begingroup\$ You are using
k
in the loop and iterating 25 times. And then using the old code, no usage ofk
. So will it actually dim the light? I haven't tested yet. \$\endgroup\$Maifee Ul Asad– Maifee Ul Asad2019年09月29日 11:41:01 +00:00Commented Sep 29, 2019 at 11:41 -
\$\begingroup\$ Now I have got it after testing it.. Can you edit the answer and help me with the
analogWrite()
type thing \$\endgroup\$Maifee Ul Asad– Maifee Ul Asad2019年09月30日 17:17:59 +00:00Commented Sep 30, 2019 at 17:17 -
\$\begingroup\$ that is a different question ... post another question \$\endgroup\$jsotola– jsotola2019年09月30日 23:07:06 +00:00Commented Sep 30, 2019 at 23:07
lang-c
analogWrite()
like thing in avr as in arduino \$\endgroup\$