Hi there, I'm having some trouble with my project here. I have two diffrent IC's ATTINY13A and ATTINY45-20SU.
When i load the code "program" listed in the bottom of this post... I get a diffrent outcome of the two IC's Using Arduino 1.0.6 and the correct librarys of both IC's
When i use the ATTINY13A @9.6Mhz i get a simple PIN0=PIN2 effect.
When i use the ATTINY45-20SU @8Mhz i get the desired hold on PIN2 until state change on PIN0...
Anybody that can help?
int inputPin = 0;
int outputPin = 2;
int inputState = 0;
int lastinputState = 0;
int outputState = 0;
void setup()
{
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
void loop()
{
inputState = digitalRead(inputPin);
if (inputState != lastinputState) {
if (inputState == 1 ) {
if (outputState==1) outputState=0;
else outputState=1;
}
lastinputState = inputState;
}
digitalWrite(outputPin, outputState);
delay(20);
}
int inputPin = 0;
int outputPin = 2;
int inputState = 0;
int lastinputState = 0;
int outputState = 0;
void setup()
{
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
}
void loop()
{
inputState = digitalRead(inputPin);
if (inputState != lastinputState) {
if (inputState == 1 ) {
if (outputState==1) {
outputState=0;
} else {
outputState=1;
}
}
lastinputState = inputState;
}
digitalWrite(outputPin, outputState);
delay(20);
}
digitalRead() is always either 0 or 1.
I would expect this to set outputPin to whatever inputPin is set to, as long as input pin is set to something. When the input pin is allowed to float, things will become unpredictable.
I suspect that that's what was happening, and why it had an anomalous "hold" effect on the '45. Frequently in the case of a floating pin, the pin will stay at it's old value for a while; you were relying on the capacitance of a floating input. Differences in process between the two parts could explain the difference.
In a well designed circuit, unless it's an antenna, you shouldn't have inputs floating - you either pull them up to Vcc or down to Gnd with a small resistor, so when nothing is touching them, they're in a known state.
If you need an output pin to follow an input pin that can be either high, low, or "don't do anything", you could put that pin at the middle of a resistor divider between Vcc and Gnd (ie, a 10k resistor from ground to input pin, and from Vcc to input pin), and use analog read.
Don't know if this will help your problem, but you need a resistor between PB2 and base of the transistor. 150 Ohms ore more. Otherwise PB2 will be shorted (almost).