Hi All
I'm have a problem with the my UNO code running on a ATTiny85.
I've run the code on a Uno without problem, but after loading it on a ATTiny85 it doesn't work as it should.
The code basically compares one analog (sensor) vs another (threshold setting), and behaves in a particular way depending on the analog value. I've run the code on my Uno and it works fine, however after loading it onto a ATTiny85, it tends to bypass one of the If else statements.
The code does run on the Attiny85, as the LED flashes the modes number (as per code) except mode 2, which just gets bypassed! As the analog voltage is increased on the sensor analog pin, it jumps from mode 1 directly to mode 3 then on to mode 4! however when I use the same code on my UNO it works properly! mode 1 - 2 - 3 - 4.
I'm using the ATTINY85 files from David A Mellis (GitHub - damellis/attiny: ATtiny microcontroller support for the Arduino IDE)
IDE 1.0.1 as requested by above software.
Tested on 3.3V and 5V, not difference
const int sensor = 3 ; // A0 On UNO
const int threshold = 4 ; // Use A1 on UNO
int shorttoground = 50; //Declare short to ground value
int shorttopositive = 975; //Declare short to positive value
int sensorValue = 0; // value read from the sensor (pot for testing purposes)
int thresholdValue = 0; // value read from the pot
int led = 1; // use 13 on UNO
int relay = 0; // use 12 on UNO
void setup() {
// initialize serial communications at 9600 bps:
// Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);
}
void loop() {
// read the analog in values:
sensorValue = analogRead(sensor);
thresholdValue = analogRead(threshold);
// Serial.print("sensor :");
// Serial.print(sensorValue);
// Serial.print(" Threshold :");
// Serial.println(thresholdValue);
if (sensorValue < shorttoground) // mode 1
{
digitalWrite(relay, LOW);
digitalWrite(led, HIGH);
delay(600);
digitalWrite(led, LOW);
}
//////// This is the one being bypassed! ////////////
else if (sensorValue >= shorttoground && sensorValue < thresholdValue) // mode 2
{
digitalWrite(relay, LOW);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
}
else if (sensorValue >= thresholdValue && sensorValue < shorttopositive) // mode 3
{
digitalWrite(relay, HIGH);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
}
else if (sensorValue >= shorttopositive) //mode 4
{
digitalWrite(relay, LOW);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
delay(200);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(led, LOW);
}
delay(500);
}
Thanks in advance!