Analog Inputs/Outputs with ATTiny 84

Hi -

I am trying to use analog inputs in a sketch with my ATTiny 84. Though my code is compiling, I’m not getting the LED to turn on.
I am using the arduino-tiny core, a windows 7 machine, and Arduino 1.0.5-r2.
Here is my code:

 const int lightPin =  0;  //define a pin for Photo resistor
 const int ledPin = 1; //define a pin for LED

void setup()
{
    pinMode( ledPin, OUTPUT );
    pinMode (lightPin, INPUT);
  }

void loop()
{
    analogWrite(ledPin, analogRead(lightPin)/4);  //send the value to the ledPin. Depending on value of resistor 
                                                //you have  to divide the value. for example, 
                                                //with a 10k resistor divide the value by 2, for 100k resistor divide by 4.
   delay(10); //short delay for faster response to light.
}

I am putting my LED on Physical Pin 12 and my Photoresistor on Physical Pin 13.

Does anybody have an accurate analog pinout for the arduino-tiny core?
Also, do you need to initialize the analog pin and how do you call analog pins?

Take a look here : http://arduino.cc/en/tutorial/blink

Why you want to use the analog pins? It can be done with analog’s too, but why? :drooling_face:

Also take a look here : http://arduino.cc/en/Tutorial/AnalogInputPins

Pin mapping

The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:

...
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
...

zaxarias:
Why you want to use the analog pins? It can be done with analog's too, but why? :drooling_face:

I want to send a variable output so that as the light from the photoresistor changes, the LED does as well.

I'm more interested in if I'm using the correct pinout.

bakkenart:

zaxarias:
Why you want to use the analog pins? It can be done with analog's too, but why? :drooling_face:

I want to send a variable output so that as the light from the photoresistor changes, the LED does as well.

Your photoresistor will go to the analog input and your led on the digital output... just take alook again on the links i posted above and here http://arduino.cc/en/Tutorial/AnalogInput..

Have a look at this chart to help you in “mapping” your pins to the correct physical pins of your tiny84.

Be aware that only the pins marked as pwm can be used as analog out.

justone:
Be aware that only the pins marked as pwm can be used as analog out.

Pwm its not analog , its digital..

" Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means "

zaxarias:

justone:
Be aware that only the pins marked as pwm can be used as analog out.

Pwm its not analog , its digital..

" Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means "
http://arduino.cc/en/Tutorial/PWM

I am very well aware of that(been an avrfreak since 2003) but to respond to someone that is new to the arduino world one should not confuse them with the details since the command to utilize pwm is called analogWrite and not digitalWrite or pwmWrite. The arduino was created for people (artists for one) that just wanted to get something to happen and not worry about how it was getting done if you were not aware of that.

For the OP since this required some fancy maneuvers to get the program onto the ATTINY84 have you at least been able to do the basic "Hello World" program of blinking an led at a certain rate?

justone:

zaxarias:

justone:
Be aware that only the pins marked as pwm can be used as analog out.

Pwm its not analog , its digital..

" Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means "
http://arduino.cc/en/Tutorial/PWM

I am very well aware of that(been an avrfreak since 2003) but to respond to someone that is new to the arduino world one should not confuse them with the details since the command to utilize pwm is called analogWrite and not digitalWrite or pwmWrite.

It's not about confusing him , it's about learning him how to code in the right way..

The arduino was created for people (artists for one) that just wanted to get something to happen and not worry about how it was getting done if you were not aware of that.

So those people should not learn the basics of programming an Arduino(at least simple coding) ? So , let me understand, i use Arduino and i do worry about how something is getting done, at the same time you tell me i shouldn't be worried about that, so i shouldn't use arduino's? you really confused me.. :~ :~ :~ :~

Sure go ahead and take my words out of context but I'm just trying to learn you. ]:smiley:

Simple coding in the world of the arduino does not require someone to fully understand the inner workings (gee like how does the pin create an output that can control something with a varying voltage). If one wants to know then nothing is stopping them to do so. But to make someone at the very beginning to understand how it is done is not what was intended.

As for yourself if you are so easily confused then maybe it's time to teach something else. ]:slight_smile:

I just told that PWM is digital and not analog, nothing more(it's wrong to tell it's analog).. And i'm totally right about that..

The post here is about analog inputs and outputs and i think it is important to know what is PWM..
I won't answer anything else out of the topic...
Thanks a lot :smiley: