Hi all,
I've been toying with my Leonardo and Mega2560 and have my simple code working fine and how I want on both ("code adapted from the Knock Sketch"). Trouble is, when I upload my code to my ATtiny13A with the pin's updated in the code, PB1 (Pin6) is "HIGH" and PB2 (pin7) is "LOW" which is all fine and well but, when I put the probe in water PB1 (Pin6) stays "HIGH" and PB2 (Pin7) is still "LOW" What I was expecting to see what PB1:LOW, PB2:HIGH as this is how it works on the Leonardo and Mega2560
Just to be clear,
The outPin's are LED's for now.
Probe out of water.
PB1:HIGH, PB2:LOW,
Probe in water.
PB1:LOW, PB2:HIGH
Leonardo code:
const int outPin1 = 7;
const int outPin2 = 8;
const int Probe = A0;
const int threshold = 75;
int sensorReading = 0;
void setup() {
pinMode(outPin1, OUTPUT);
pinMode(outPin2, OUTPUT);
Serial.begin(9600);
}
void loop() {
sensorReading = analogRead(Probe);
Serial.print("\t sensor = " );
Serial.print(sensorReading);
if (sensorReading >= threshold) {
digitalWrite(outPin1, HIGH);
digitalWrite(outPin2, LOW);
}
else {
digitalWrite(outPin1, LOW);
digitalWrite(outPin2, HIGH);
}
delay(100);
}
ATtiny13A:
const int outPin1 = 1;
const int outPin2 = 2;
const int Probe = 0;
const int threshold = 75;
int sensorReading = 0;
void setup() {
pinMode(outPin1, OUTPUT);
pinMode(outPin2, OUTPUT);
}
void loop() {
sensorReading = analogRead(Probe);
if (sensorReading >= threshold)
{
digitalWrite(outPin1, HIGH);
digitalWrite(outPin2, LOW);
}
else {
digitalWrite(outPin1, LOW);
digitalWrite(outPin2, HIGH);
}
delay(100);
}
I can only assume some things up with my code, in fact... My assumption is, PB0 to PB5 can be ether used as Analogue or Digital I/O's? Is this correct?
I'll put up an Fritzing pic in a sec.
If there's anything thing have missed out, shout.
Cheers,