a question on one of Nick Gammons tutorials


This is the tutorial. It's pretty Cool. In an effort to better my understanding I have a couple questions.

In the tutorial he uses a ATTiny85 in the "build". But there is this sentence

"There is a bit of conditional code to allow for testing on a Uno, BEFORE migrating to the Attiny85."

Looking at the code, specifically PIN declarations. It says

const byte LED = 0; // pin 5
const byte LDR_ENABLE = 3; // pin 2
const byte LDR_READ = 1; // Ain1 (PB2) pin 7

I'm confused.

is const byte LED = 0 // IS THAT LOW?
is const byte LDR_ENABLE = 3 // pin 3 on the 328?
is const byts LDR_READ = 1 // pin 7 on the Tiny?

led = 0, //is pin 5
enable = 3, // is pin 2 on the 328
read = 1, / /is Ain2 (PB2) pin 7

I don't get it, can some one explain? Thanks

It can be confusing when pins have different numbers for Digital and Analog.

Digital pin 0 is on physical pin 5.
Digital pin 3 is on physical pin 2.
Analog input pin 1 (or A1) is on physical pin 7 (same physical pin as Digital pin 2)

If you run the code on an UNO you will be using the pins marked D0, D3, and A1.

thanks John. it can be confusing no doubt.

Mr. Wasser,

In Mr. Gammons sketch several times it noted #if definded(AVR_ATtiny85). Is this something that that "libraries" take into consideration when processing commands?

Should those lines be changes to #if defined(AVR_ATMega328P)? when working with a bare bones ATMega 328P-PU chip?

Just trying to expand my understanding.


No, that is the "bit of conditional code to allow for testing on a Uno" that Nick mentions.

if(this is true)
  run this bit of code;
else  // its not true
  so run this bit of code instead;

is that a drop top GTO? either way an AWESOME sled.

I wired everything up as defined in the tutorial. However it doesn't work as expected.

I get the pulse from D3 every 2 seconds (hooked it up to an LED) that's supposed to allow for the analog read on A1.. I'm using a sparkfun board, and D0 is noted as "RX" I actually need that pin for my project.

and didn't quite understand this line from Mr. Wasser's post

"Analog input pin 1 (or A1) is on physical pin 7 (same physical pin as Digital pin 2)"

I have my voltage divider (between the 56K and the LDR) going to A1. D3 to the other side of the LDR. And power to the LED comes from D0. (at least it is supposed to).

the resistance on the voltage divider is 23 ohms in the light and 48 ohms in the dark. and it reads quickly.

what could be causing a malfunction?


it was the threshold. a small experiment was all that was required. it WORKS. though I did change the LED to pin 13 to free up the RX

Glad you figured it out! and yeah it's a '65 I helped restore.

Hey guys, building Mr. Gammons project works as intended on my bare bones ATMega 328. Thanks for your help.

He did an excellent job in power consumption. BUT! I would like to undue part of it. It seems the only pin that is awake when it is dark is the blinking LED pin, which makes perfect sense. This power down stuff is really new to me and complicated. I am hoping one of ya'll can help with a modification?

The LED that currently blinks, that pin, will be used to switch on a NPN 3904 to power (from a separate source) an Adafruit FX Sound Board. I can successfully turn the FX board using this pin on and off for any given amount of time. However I have no serial control over the FX board because everything else is shut down.

My objective seems simple enough. Instead of a blinking LED. To power a sound board make it play instead of blink go to sleep for awhile, make it play instead of blink... then at day power down the whole thing as does the LED.

It's confusing because there are 2 different sleep/power down modes being used. Is it possible to accomplish?


NEVERMIND, I got lucky and figured it out. But I still have a question about arrays but I have to go study them for awhile.