Can be deleted or moved Programming ATTINY85 with Uno

Hi, I am trying to compile the sketch below but I cannot compile or upload to the ATTINY85 chip when I choose ATTINY85 (arduino as ISP) from the board menu. The error log of Arduino IDE is also below. What is the problem?

Note: I have uploaded the Arduino ISP sketch to the uno already.

int analogPin = 3;     // Data cable connected to the analog pin
int YelLED=1;  // yellow LED pin for Temp>36
int RedLED=0;  //red LED pin for Temp>40
int Fan=2;     //Fan connected to the MOSFET will be high Temp>37
float val = 0;           // variable to store the value read

void setup(){
  pinMode(YelLED, OUTPUT);
  pinMode(RedLED, OUTPUT);
  pinMode(Fan, OUTPUT);
  
   function1(); //for the temperatures lower than 30 and higher than 25
   function2(); //for the temperatures higher than 30
   function3(); //for the temperatures higher than 30
}

void loop(){
  float val=0;
   val = analogRead(analogPin)*0.48828125;  
      digitalWrite(YelLED, LOW);
      digitalWrite(RedLED, LOW);
      digitalWrite(Fan,LOW);
      
  if(val>=36 && val<40){
  function1();}

  if(val>40){
  function2();
  function3();} 
  delay(1000);
}

void function1(){ //function which should work only in 25-30 degrees
  digitalWrite(YelLED, HIGH);
//  delay(1000);
//  digitalWrite(YelLED,LOW);
//  delay(1000);
}

void function2(){ //funtion which should work only after 30 degrees
  digitalWrite(RedLED,HIGH);
  digitalWrite(YelLED, HIGH);
//  delay(1000);
//  digitalWrite(RedLED,LOW);
//  delay(1000);
}

void function3(){ //funtion which should work only after 30 degrees
  digitalWrite(Fan,HIGH);
  //delay(3000);
}

I can't help you with the uploading problem, but I do have to wonder why you call function1(), function2(), and function3() from setup(), and why the functions have such useless names.

Why do you have two functions for when the temperature is over 30?

How would you remember what function to use if analogRead() was called function9385()?

int YelLED=1;  // yellow LED pin for Temp>36
int RedLED=0;  //red LED pin for Temp>40

Then why isn't pin in the name?

Why are the { and } jammed tight up against the statements in the block. Spacesmakeformuchmorereadablecode.

PaulS: Why do you have two functions for when the temperature is over 30?

I have not corrected the comments yet. if you follow the code, you can see that they operate in different temperature conditions

PaulS: How would you remember what function to use if analogRead() was called function9385()?

The code is not complicated, I can scroll back and check but for a complicated project, it could be better to use a systematic names.

PaulS: int YelLED=1;  // yellow LED pin for Temp>36 int RedLED=0;  //red LED pin for Temp>40

Then why isn't pin in the name?

I could not get this one and next one? As far as the code works on the arduino, does it really matter how I use the spaces or pin in the pin tags?

PaulS: Why are the { and } jammed tight up against the statements in the block. Spacesmakeformuchmorereadablecode.

Why did I use the functions in the void setup? They did not work unless I defined them in the void setup

Cheers, Oz

I think you'll find that PaulS, when it comes to C coding experience, is two years younger than dirt. He's simply offering you good coding advice to make your job simpler down the road. You should really take what he says to heart. Indeed, when you see someone write you a comment with over 43,000 posts and that many Karma points, you probably need to take heed of what they are saying.

econjack: I think you'll find that PaulS, when it comes to C coding experience, is two years younger than dirt. He's simply offering you good coding advice to make your job simpler down the road. You should really take what he says to heart. Indeed, when you see someone write you a comment with over 43,000 posts and that many Karma points, you probably need to take heed of what they are saying.

I got the advice, no worries, the code will be better, when I finish my trials for sure. But the I am looking for an answer for a different problem here...

Did I post the thread in a wrong section of the forum?

I think you’ll find that PaulS, when it comes to C coding experience, is two years younger than dirt.

Hey, are you implying I’m old? I resemble that remark.

They did not work unless I defined them in the void setup

You are not defining the functions in setup() (NOT void setup; that grates on my ears). You are calling them.

If you can’t even get the code loaded on the tiny, how do you know it doesn’t work?

Did I post the thread in a wrong section of the forum?

No. This is the proper place. Just bear in mind that the ATTiny85 is not an Arduino, so you’ll get less help than with a a real Arduino.

The error log of Arduino IDE is also below.

Below what? Did I miss something?

I would suggest that the first error line is a pretty big clue. It cannot find a file. As to why, I can't really help you but once you resolve that issue most of the other errors will disappear.

It looks as if some library file (perhaps the core library for the Attiny85) is missing or can't be found.

What have you done to make it possible to compile code for the Atting85?

Can you provide a link to the instructions you are following?

...R

PaulS: If you can't even get the code loaded on the tiny, how do you know it doesn't work?

Hi Paul,

It works when I choose the Arduino uno as the board, compiles, uploads, works if i connect the temperature sensor to the analog pin. the problem is when i choose attiny85 (Arduino as ISP) from the board menu.

I moved the thread to the microcontrollers section. I will be glad if you can follow the topic there. http://forum.arduino.cc/index.php?topic=214967.0

Cheers, Oz

Thanks for the answers everybody. I moved the thread to the microcontrollers seciton. I will be glad if you follow the topic there. http://forum.arduino.cc/index.php?topic=214967.0

Cheers, Oz