//#include <dht.h>
#include<IRremote.h>
#include<LiquidCrystal.h>
#include"DHT.h"
#include<Stepper.h>
int stepsPerRevolution=200;
int motSpeed=20;
Stepper myStepper(stepsPerRevolution,28,30,29,31);
#define DHTTYPE DHT22
#define DHTPIN 53
DHT dht(DHTPIN, DHTTYPE);
//#include <MD_Parola.h>
#include <MD_MAX72xx.h>
int Cnt=0;
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 1
#define CS_PIN 4
#define DATA_PIN 3
#define CLK_PIN 2
//MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE,DATA_PIN,CLK_PIN, CS_PIN, MAX_DEVICES);
#include <MaxMatrix.h>
int DIN = 3; // DIN pin of MAX7219 module
int CLK = 2; // CLK pin of MAX7219 module
int CS = 4; // CS pin of MAX7219 module
int maxInUse = 1;
MaxMatrix m(DIN, CS, CLK, maxInUse);
int cntde=0;
int receiver = 51; //IR receiveer pin
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
int ledState = LOW;
unsigned long previousMillis = 0;
const float BETA = 3950;
int temp2=0;
float f=0; //tempF
float t=0; //tempC
float h=0; //humidity
int blueled=0;
int rev=0;
void setup() {
irrecv.enableIRIn(); // Start the receiver
// Intialize the LCD object:
//myDisplay.begin();
// Set the intensity (brightness) of the display (0-15):
//myDisplay.setIntensity(0);
// Clear the display:
//myDisplay.displayClear();
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.begin(16,2);
dht.begin();
myStepper.setSpeed(motSpeed);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(49,OUTPUT);
m.init(); // MAX7219 initialization
m.setIntensity(0); // initial led matrix intensity, 0-15
}
//char inread[10];
int cnt2=0;
int first=1;
void loop() {
if(Serial.available() > 0)
{
//str = Serial.readStringUntil('\n');
cntde = Serial.parseInt();
cnt2=cntde/1.8;
// Serial.println(cnt2);
}
//Cnt=0;
if(Cnt==1){
if(first==1){cnt2=cnt2+2;
first=0;
}
if(cnt2>0){
if(rev==1){
myStepper.step(-1);
}
else{
myStepper.step(1);
}
Serial.println(cnt2);
cnt2--;
}
}
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
Serial.println(results.value,HEX);
}
//Read humitidy
h = dht.readHumidity();
// Read temperature as Celsius (the default)
t = dht.readTemperature(false);
//Read temperature as Fahrenheit (isFahrenheit = true)
f = dht.readTemperature(true);
unsigned long currentMillis = millis();
int mypot=0;
float mytemp=0;
mypot=analogRead(A0); //Read pots wiper voltage as 0 to 1023 10 bit ad converter
mytemp=analogRead(A1); //read the analog tempeture sensor
// convert temp sensor voltage to degrees C
float celsius =1/ (log(1 / (1023. / mytemp - 1)) / BETA + 1.0 / 298.15) - 273.15;
//myDisplay.setTextAlignment(PA_CENTER);
//myDisplay.setIntensity(0);
float voltage=mypot*(5.0/1023.0); // convert alalog steps to voltage
/*Serial.print("Temperature = ");
Serial.println(f,2);
Serial.print("Humidity = ");
Serial.println(h,2);
Serial.print( "cnt ");
Serial.println(cnt);
*/
lcd.setCursor(0, 1);
lcd.print(voltage);
lcd.setCursor(6,1);
lcd.print(f);
lcd.setCursor(6, 0);
lcd.print(t);
lcd.setCursor(0, 0);
char buffer1[10];
char buffer2[20];
//celsius=(celsius*1.8)+32;
//dtostrf(celsius,4,2,buffer2);
sprintf(buffer1, "%4d", mypot); // 4 trailing spaces
lcd.print(buffer1);
lcd.setCursor(12,0); // print humitidy
lcd.print(h,1);
cntde++;
/*if (cntde>2){
m.setColumn(3,61);// ease d
cntde=0;
}
//draw arm up
m.setDot(0,3,1);
m.setDot(6,3,1);
delay(500);
//erase arm up
m.setDot(0,3,0);
m.setDot(6,3,0);
//dram arm down
m.setDot(0,5,1);
m.setDot(6,5,1);
delay(500);
//erase arm down
m.setDot(0,5,0);
m.setDot(6,5,0);
*/
//the voltage at the pots wiper detrmins the blink speed lower=faster
if (currentMillis - previousMillis >= (mypot)) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if (ledState ==LOW) {
ledState = HIGH;
//myDisplay.print("H");
myprintL();
lcd.setCursor(12, 1); //Print this to lcd here to slow it down to the blink rate
lcd.print(celsius); //celsius has been convert to F }
}
else {
ledState = LOW;
//myDisplay.print("L");
myprintH();
}
}
digitalWrite(5, !ledState);
digitalWrite(6, ledState);
}
void myprintL(){
m.setColumn(7,15);
m.setColumn(6,9);
m.setColumn(5,15);
m.setColumn(4,30);//with d 61=no d 253=d
m.setColumn(3,10);
m.setColumn(2,250);
m.setColumn(1,80);
m.setColumn(0,80);
//return;
}
void myprintH(){
m.setColumn(7,0);
m.setColumn(6, 0);
m.setColumn(5,239);
m.setColumn(4,41);//with d 61=no d 253=d
m.setColumn(3,73);
m.setColumn(2,239);
m.setColumn(1,0);
m.setColumn(0,0);
}
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch(results.value)
{
case 0xFF45BA: togLed(); break;
case 16769565: Serial.println("FUNC/STOP"); break;
case 0xFF629D: ledoff(); break;
case 0xFF47B8: rev=1; break;
case 0xFF02FD: Serial.println("PAUSE"); break;
case 0xFFC23D: Serial.println("FAST FORWARD"); break;
case 0xFFE01F: Serial.println("DOWN"); break;
case 0xFFA857: Serial.println("VOL-"); break;
case 0xFF906F: Serial.println("UP"); break;
case 0xFF9867: Serial.println("EQ"); break;
case 0xFFB04F: Serial.println("ST/REPT"); break;
case 0xFF6897: Serial.println("0"); break;
case 0xFF30CF: Serial.println("1"); break;
case 0xFF18E7: Serial.println("2"); break;
case 0xFF7A85: Serial.println("3"); break;
case 0xFF10EF: Serial.println("4"); break;
case 0xFF38C7: Serial.println("5"); break;
case 0xFF5AA5: Serial.println("6"); break;
case 0xFF42BD: Serial.println("7"); break;
case 0xFF4AB5: Serial.println("8"); break;
case 0xFF52AD: togLed(); break;
case 0xFFFFFFFF: Serial.println(" REPEAT");break;
default:
Serial.println(results.value,HEX);
}// End Case
}
void ledon(){
digitalWrite(49,1);
}
void ledoff(){
digitalWrite(49,0);
}
void togLed(){
if (blueled==0){
blueled=1;
digitalWrite(49,blueled);
Serial.print("blue ");
Serial.println(blueled);
Cnt=1;
rev=0;
//delay(1000);
} else{
blueled=0;
digitalWrite(49,blueled);
Serial.print("blue ");
Serial.println(blueled);
Cnt=0;
}
}