Tuesday, April 5, 2016

Attiny85 timer

First post here!
Building a timer for my UV light PCB making apparatus. Posting now the code for Arduino Micro. Using 6250 bytes of memory, so should have no issues to load this to Attiny85 with required pin designation changes. This code uses same analog input to both read the time setting from a regular potentiometer as well as the input for the start/stop button. This maximizes the IC limited I/O pins. The Serial Print commands are not required and my updated code will include instead a serial print to a 4 digit display module (SCL and SDA lines) to show the actual time set and count down information.
I'll be posting the updated code for Attiny85 pinout and schematic. The code allows a time adjust from 0 to 240 seconds, but can be expanded with a simple code change.
Yes, complete overkill to use a micro controller for a simple timer, just trying to learn Arduino coding by building basic projects. Plus, Attiny85 are very cheap these days!

Here's the code for now.

#include <elapsedMillis.h>

elapsedMillis timer=0;
int timer2=0;
int p=0;
void setup() {
pinMode(A0,INPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
digitalWrite(13,LOW);
Serial.begin(9600);
timer=0;
}
void loop() {
if(analogRead(A0)>200){
timer2=constrain(map(analogRead(A0),515,1023,0,240),0,240);
}
if (analogRead(A0)<100){//C
p=1;
delay(100);
}
if(digitalRead(13)==HIGH)
{
Serial.print("timeleft=");
Serial.println(timer2-timer/1000);
delay(100);
}
else
{
Serial.print("time=");
Serial.println(timer2);
delay(100);
}
if (p==1){//D
if (analogRead(A0)>200){//C
digitalWrite(13,!digitalRead(13));
timer=0;
p=0;
delay(500);
}//C
}//D
if ((timer/1000)>timer2 ){//G
digitalWrite(13,LOW);
}//G
}

Here's the schematic in Eagle:


















No comments:

Post a Comment