#include "TimerOne.h" #include #include #define LATCH 3 #define CLOCK 2 #define DATA 4 dht DHT; const int mSteps = 32; const int gSteps = 64; Stepper stepper(mSteps, 8, 10, 9, 11); /* -0- 5 1 -6- 4 2 -3- (7) */ unsigned char LED_BCD[16] = { 0xc0,0xf9,0xa4,0xb0, //0123 0x99,0x92,0x82,0xf8, //4567 0x80,0x90,0x88,0x83, //89AB 0xc6,0xa1,0x86,0x8e };//CDEF char H = 0x89; volatile int temperature=0; volatile int humidity=0; bool airing = false; // variable to store the servo position int openAt = 70; int closeAt = 60; int openSteps = mSteps*gSteps; void setup() { pinMode(LATCH, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(DATA, OUTPUT); Serial.begin(115200); Timer1.initialize(5500); Timer1.attachInterrupt(leddisplay); stepper.setSpeed(500); delay(2000); stepper.step(openSteps); delay(2000); stepper.step(-openSteps); } void leddisplay() { static unsigned char digit = 0; static unsigned int q=0; unsigned char c0; int m = millis(); if(digit == 0) { if(m & 4096) { q = temperature; c0 = LED_BCD['c']; } else { q = humidity; } } digitalWrite(LATCH, LOW); shiftOut(DATA, CLOCK, MSBFIRST, LED_BCD[q % 10]); q/=10; shiftOut(DATA, CLOCK, MSBFIRST, 1< openAt && !airing) { Serial.println("opening!"); stepper.step(openSteps); airing = true; } else if(humidity < closeAt && airing) { Serial.println("closing!"); stepper.step(-openSteps); airing = false; } } }