#include <IRremote.h>
#include <Servo.h>
#include <LiquidCrystal.h>
#define PIN_RECEIVER 12
#define PIN_SERVO 3
#define NOTE_C1 33
#define NOTE_D1 37
#define NOTE_A1 55
#define NOTE_B1 62
IRrecv receiver(PIN_RECEIVER);
Servo servo1;
LiquidCrystal lcd( 11, 10, 9, 8, 7,4);
const float BETA = 3950;
int bz=6;
int ledpin=5;
int inpin=2;
int val;
void setup() /*servo*/
{
pinMode(ledpin, OUTPUT);
pinMode(inpin, INPUT_PULLUP);
lcd.begin(10, 8);
lcd.print("!!!");
Serial.begin(9600);
receiver.enableIRIn();
servo1.attach(PIN_SERVO);
pinMode(bz, OUTPUT);
digitalWrite(ledpin, LOW);
}
int rotation = 90;
int flag=0; //不转 0 1转自动转
int ledflag=0;
void loop()
{
delay(100);
val=digitalRead(inpin);
if( val==LOW )
{
if(ledflag==0)
ledflag=1;
else
ledflag=0;
}
if(ledflag==1)
{
digitalWrite(ledpin, HIGH);
}
else
{
digitalWrite(ledpin, LOW);
}
if (receiver.decode()) {
if (receiver.decodedIRData.command == 224) // 224 "PREV."键 左 ---
{
flag=0;
Serial.println("PREV");
rotation = rotation - 10;
if (rotation < 0) rotation = 0;
servo1.write(rotation);
}
if (receiver.decodedIRData.command == 144) // 144 "NEXT."键 右 +++
{
flag=0;
Serial.println("NEXT");
rotation = rotation + 10;
if (rotation > 180) rotation = 180;
servo1.write(rotation);
}
receiver.resume();
}
delay(200);
int analogValue = analogRead(A0) ;
float wendu = 1/(log(1/(1023./analogValue -1)) /BETA + 1.0/298.15) - 273.15;
lcd.setCursor(2,1);
lcd.clear();
lcd.print("tmp: "+String(wendu));
//Serial.println("tmp2:");
if(wendu>30 or wendu<5)
{
Serial.println("tmp2:"+String(wendu));
delay(10);
tone(bz,3729,200);
//delay(200);
tone(bz,NOTE_A1,200);
//delay(200);
tone(bz,1319,200);
//delay(200);
tone(bz,NOTE_C1,200);
//delay(200);
tone(bz,988,200);
//delay(200);
}
else
{
noTone(bz);
}
}