2

I am new here and perhaps you could help me. I am trying to program Attiny13 with the following short sketch which uses ADC (analogread()) function, that is supposed to work like this:

  • reads voltage from voltage divider using photoresistor - analogread() from A1 (ADC1)
  • turns LED on/off whenever there is low light (covering photoresistor) - digitalwrite() LED at 3 (PB3)

however it does not work on each of the ADCs: - works when I use A3 (ADC3) as analogread - does not work when I use A1 (ADC1) or A2 (ADC2) as analogread

Do you know what might be the reason? Same code, but works on 1 of the ADCs only.

I program uC with USBASP programmer, but I don't think this matters since with 1 of the ADCs all works fine. Also it works on Arduino Mega 2560 and uC Atmega88, so something wrong with Attiny13.

Sketch that does not work:

int state = 0;


void setup() 
{
pinMode(3, OUTPUT);  
}


void loop() 
{
    int reading = analogRead(A1); 

    if (reading < 100) // ONCE I COVER PHOTORES. IT GOES INTO THIS LOOP AND TURNS ON/OFF THE LED
    {
        state = !state;
        digitalWrite(3, state);
        delay(200);
    }

    delay(100);
}
KIIV
  • 4,907
  • 1
  • 14
  • 21
marek
  • 21
  • 2

0 Answers0