Termostat (2 / 2 steg)
Steg 2: Lägg till kod
#include
#include int tempPin = A0; int ledde = 13. float härda; float settemp; int swtu = 7. int swtd = 6; LiquidCrystal lcd (12, 11, 5, 4, 3, 2); void setup() {pinMode (led, 1). Serial.BEGIN (9600); LCD.BEGIN (16, 2); lcd.setCursor (0, 0); LCD.Print ("hello, world!"); LCD.Clear(); EEPROM.read (1). }
void loop() {int tvalue = analogRead(tempPin); flyta temp = (tvalue / 6.388888888889), lcd.setCursor (0, 0), lcd.print (temp), lcd.print 'F'. Serial.println (temp); settemp = EEPROM.read(1); fördröjning (250); om (digitalRead(swtu) == 1) {settemp ++;} annat {} om (digitalRead (swtd) == 1) {(settemp--);} annat {} om (temp > settemp) {digitalWrite (led, 1);} annat {digitalWrite (led, 0);} lcd.setCursor (0, 1); 4 lcd.print ("in till"); LCD.Print (settemp); LCD.Print 'F'. Serial.println(settemp); EEPROM.write (1, settemp); fördröjning (250); }