I am planning on using a ATtiny85 to control 3 separate 12V LED strips (each strip has built in resistors to control current).
Everything is powered from one 12V 5A power supply. A 5V voltage regulator is used to supply 5v power to the ATtiny85 and the PIR motion sensor. The output from the sensor (3.3VDC) is sent to PB2 on the ATtiny85, and this starts turning on the three 12V LED strips at different intervals using PWM output on PB0, PB1, and PB4.
Should I use digital read (high/low) or analog read for PB2 since the sensor outputs 3.3VDC?
I have programing experience in Arduino but this is my first ATtiny project.
Thanks!!
This is the basic code that I am going to use. I know I have to declare & add the input for PB2.
/* Three PWM Outputs */
// ATtiny85 outputs
const int LEDone = 0;
const int LEDtwo = 1;
const int LEDthree = 2;
volatile uint8_t* Port[] = {&OCR0A, &OCR0B, &OCR1B};
int Pin[] = {0, 1, 4};
void setup() {
pinMode(Pin[LEDone], OUTPUT);
pinMode(Pin[LEDtwo], OUTPUT);
pinMode(Pin[LEDthree], OUTPUT);
// Configure counter/timer0 for fast PWM on PB0 and PB1
TCCR0A = 3<<COM0A0 | 3<<COM0B0 | 3<<WGM00;
TCCR0B = 0<<WGM02 | 3<<CS00; // Optional; already set
// Configure counter/timer1 for fast PWM on PB4
GTCCR = 1<<PWM1B | 3<<COM1B0;
TCCR1 = 3<<COM1A0 | 7<<CS10;
}
// Sets light LEDone=0 LEDtwo=1 LEDthree=2 to specified intensity 0 (off) to 255 (max)
void SetLight (int light, int intensity) {
*Port[light] = 255 intensity;
}
void loop()
{
for (int light=0; light<3; light++)
{
SetLight((light+2) % 3, 0);
for (int i=0; i <= 255; i++) {
SetLight((light+1) % 3, i);
SetLight(light, 255i);
delay(25);
}
}
}
[CODE]