ATTiny84 + LCD + LM35 temperatur sensor (2 / 4 steg)
Steg 2: Skapa krets och testa
Från början detta projekt skulle använda ATtiny85 och en 74HC595 SKIFT register men på grund av problem med USI SPI jag skränande få dem att fungera så jag bara bytte till en ATtiny84 byter ut.
Banan byggdes ursprungligen runt Arduino Uno under koden utveckling och sedan bytte jag stiften för att passa den en jag använd på den Attiny84, som fortfarande fungerar utan problem på Uno.
Koden för projektet ingår nedan: (uppdaterad med Fahrenheit och Kelvin-läge)
#include < avr/sleep.h >
#include < LiquidCrystal.h >
LiquidCrystal lcd (10, 9, 8, 7, 6, 5);
byte grad [8] = {
0b00000,
0b11100,
0b10100,
0b11100,
0b00000,
0b00000,
0b00000,
};
CONST int buttonPin = 1; PIN-koden som tryckknappen fästs
CONST int tempPin = 0;
CONST långa intervall = 500. fördröjning i millisekunder för temperatur läsning att uppdatera
osignerade långa previousMillis = 0;
int buttonState; aktuell status för knappen
int lastButtonState; tidigare tillstånd av knappen
flyta tempC = 0;
flyta tempF = 0;
flyta tempK = 0;
int läsa = 0;
osignerade långa pwrofftime = 600000; första gången innan stängs av i millisekunder
int tempmode = 0; 0 = celcius, 1 = fahrenheit, 2 = kelvin
void setup() {
analogReference(INTERNAL); anger referensspänningen för Arduino's ADC till 1,1 volt
pinMode (buttonPin, ingång);
LCD.BEGIN (8, 2);
lcd.createChar (8, grad);
lcd.setCursor (0, 0);
LCD.Print("Hello");
lcd.setCursor (0, 1);
LCD.Print("World!");
Delay(1000);
}
void loop() {
buttonState = digitalRead(buttonPin);
osignerade långa currentMillis = millis();
om (buttonState! = lastButtonState) {
om (buttonState == låg) {
LCD.Clear();
tempmode = tempmode + 1.
om (tempmode > 2) {
tempmode = 0;
}
IF(tempmode == 0) {
lcd.setCursor (0, 0);
LCD.Print("Celsius");
lcd.setCursor (0, 1);
LCD.Print("mode");
}
annat if(tempmode == 1) {
lcd.setCursor (0, 0);
LCD.Print("Fahrenhe");
lcd.setCursor (0, 1);
LCD.Print ("it läge");
}
annat if (tempmode == 2) {
lcd.setCursor (0, 0);
LCD.Print("Kelvin");
lcd.setCursor (0, 1);
LCD.Print("mode");
}
}
pwrofftime = pwrofftime + currentMillis;
Delay(500);
lastButtonState = buttonState;
}
om (currentMillis - previousMillis > = intervall) {
previousMillis = currentMillis;
int läsa = analogRead(tempPin);
tempC = läsning / 9,31;
tempF = (9/5) * tempC + 32;
tempK = tempC + 273.15;
lcd.setCursor (0, 0);
IF(tempmode == 0) {
LCD.Print ("TempC:");
lcd.setCursor (0, 1);
LCD.Print(tempC);
LCD.write(8);
LCD.Print ("C").
}
annat if(tempmode == 1) {
LCD.Print ("TempF:");
lcd.setCursor (0, 1);
LCD.Print(tempF);
LCD.write(8);
LCD.Print "F".
}
annat if(tempmode == 2) {
LCD.Print ("TempK:");
lcd.setCursor (0, 1);
LCD.Print(tempK);
LCD.write(8);
LCD.Print ("K");
}
}
IF(pwrofftime < currentMillis) {
Sleep();
}
}
void sleep() {
lcd.setCursor (0, 0);
LCD.Print("Powering");
lcd.setCursor (0, 1);
LCD.Print ("ner...");
Delay(1000);
lcd.setCursor (0, 0);
LCD.Print ("Powered");
lcd.setCursor (0, 1);
LCD.Print ("nedåt.");
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
}