Az IRRemote a következő:
IRremote
// Version 2.0.1 June, 2015
// Copyright 2009 Ken Shirriff
// For details, see
http://arcfn.com/2009/08/multi-protocol ... brary.html
// Edited by Mitra to add new controller SANYO
//
// Interrupt code based on NECIRrcv by Joe Knapp
Íme a program jelenlegi állapota, INT-tel, a helyzet nem változott, de sanszos, hogy a kínai távirányító lesz a ludas...:
Kód: Egész kijelölése
#include <SoftwareSerial.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include <TinyGPS++.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <BH1750.h>
#include <IRremote.h>
#define DISPLAY_ADDRESS 0x70 //time display's address
#define CLK_YEAR 3 //clock pin for year display
#define DIO_YEAR 4 //digital I/O pin for year display
#define CLK_DATE 5 //clock pin for date display
#define DIO_DATE 6 //digital I/O pin for date display
TM1637Display yearDisplay(CLK_YEAR, DIO_YEAR);
TM1637Display dateDisplay(CLK_DATE, DIO_DATE);
Adafruit_7segment clockDisplay = Adafruit_7segment();
SoftwareSerial ss(8, 7); // GPS breakout/shield will use a
// software serial connection with
// TX = pin 8 and RX = pin 7.
TinyGPSPlus gps;
BH1750 lightMeter;
volatile int ertek;
int RECV_PIN = 2; // IR receiver's digital pin
volatile int HOUR_OFFSET = 2; // Default time zone
volatile int SYS_STATE = 0; // Clock is running without alarm time, deafult state after power on
volatile int AL_HOUR = 0; // Variable for alarm hour
volatile int AL_MIN = 0; // Variable for alarm minute
volatile int AL_TIME = 0; // Variable for alarm time
int ev; // Variable for the year on yeardisplay
int honap; // Variable for the month on datedisplay
int nap; // Variable for the day on datedsplay
int hours; // Variable for hours on clockdisplay
int minutes; // Variable for minutes on clockdisplay
int seconds; // Variable for seconds on clockdisplay
int e_ev; // Variable for the previous year
int e_honap; // Variable for the previous month
int e_nap; // Variable for the previous day
volatile int bright_shift = 2; // Variable for power (and bright) saving mode
int displayValue = 0; // Variable for displayed value on the clockdisplay
volatile int lang = 0; // Variable for datedisplay's language (YYYY-MM-DD -> MM-DD-YYYY -> DD-MM-YYYY
int lux; // Variable for lightmeter' lux value
int bright; // Variable for brightness of the year and date
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
// Setup Serial port to print debug output.
//Serial.begin(115200);
//Serial.println("Clock starting!");
clockDisplay.begin(DISPLAY_ADDRESS); // Setup the display
ss.begin(9600); // Setup the GPS using a 9600 baud connection
lightMeter.begin(); // Setup the lightmeter
irrecv.enableIRIn(); // Setup te IR receiver
attachInterrupt(0, read, CHANGE);
}
void loop() {
if (SYS_STATE % 2 == 0) // Date and time displaying without or with alarm time set
{
clockDisplay.blinkRate(0);
// Dispatch incoming characters
while (ss.available() > 0)
gps.encode(ss.read());
if (gps.time.isUpdated())
{
hours = gps.time.hour() + HOUR_OFFSET; // Add hour offset to convert from UTC
// to local time.
// Handle when UTC + offset wraps around to a negative or > 23 value.
if (hours < 0) {
hours = hours+24;
}
if (hours > 23) {
hours = hours-24;
}
minutes = gps.time.minute();
seconds = gps.time.second();
// Show the time on the display by turning it into a numeric
// value, like 3:30 turns into 330, by multiplying the hour by
// 100 and then adding the minutes.
displayValue = hours*100 + minutes;
if (gps.time.hour() == 23 && gps.time.minute() == 59 && gps.time.second() == 59 && HOUR_OFFSET < 0)
{
e_ev = gps.date.year();
e_honap = gps.date.month();
e_nap = gps.date.day();
}
clockDisplay.print(displayValue, DEC);
// Add zero padding when in 24 hour mode and it's midnight.
// In this case the print function above won't have leading 0's
// which can look confusing. Go in and explicitly add these zeros.
if (hours == 0) {
// Pad hour 0.
clockDisplay.writeDigitNum(1, 0);
// Also pad when the 10's minute is 0 and should be padded.
if (minutes < 10) {
clockDisplay.writeDigitNum(3, 0);
}
}
// Blink the colon by turning it on every even second and off
// every odd second. The modulus operator is very handy here to
// check if a value is even (modulus 2 equals 0) or odd (modulus 2
// equals 1).
if (SYS_STATE == 2)
{
if (seconds % 2 == 0)
{
clockDisplay.writeDigitRaw(2, 0x06);
}
else
{
clockDisplay.writeDigitRaw(2, 0x04);
}
}
else
{
clockDisplay.drawColon(seconds % 2 == 0);
}
}
lux = lightMeter.readLightLevel(); // read the environment brightness
clockDisplay.setBrightness(int(lux/10)+bright_shift); // set clockdisplay brightness
// Now push out to the display the new values that were set above.
if (displayValue == AL_TIME and SYS_STATE == 2) // Alarming!!!
{
clockDisplay.setBrightness(15);
clockDisplay.blinkRate(1);
// here will be written the alarm music :)
}
clockDisplay.writeDisplay();
bright = int(lux/30)+6+bright_shift;
if (bright > 10)
{
bright = 10;
}
yearDisplay.setBrightness(bright); //set yeardisplay brightness
dateDisplay.setBrightness(bright); //set datedisplay brightness
if (gps.date.isUpdated())
{
ev = gps.date.year();
honap = gps.date.month();
nap = gps.date.day();
if (gps.time.hour()+HOUR_OFFSET > 23) // If there is the next day after Greenwich Main Time cause hour offset
{
nap++;
if (nap == 32) // At the end of the a 31-day-month
{
honap++;
nap=1;
if (honap == 13)
{
ev++;
honap=1;
}
}
if (nap == 31 && (honap == 4 || honap == 6 || honap == 9 || honap == 11 )) // At the end of the a 30-day-month
{
nap=1;
honap++;
}
if (nap == 30 && honap == 2) // At the end of a 29-day-februar
{
nap=1;
honap=3;
}
if (nap == 29 && honap == 2 && (ev % 4 != 0 || ev % 400 == 0)) // At the end of a 28-day-februar
{
nap=1;
honap=3;
}
}
if (gps.time.hour()+HOUR_OFFSET < 0) // If there is the previous day before Greenwich Main Time cause hour offset
{
ev = e_ev;
honap = e_honap;
nap = e_nap;
}
if (lang == 0 ) // Hungarian sequence: YYYY. MM. DD.
{
yearDisplay.showNumberDecDot(ev, false, 4, 0, 4); // push out the year
dateDisplay.showNumberDecDot(100*honap+nap, true, 4, 0, 1); // push out the date
}
if (lang == 1 ) // English sequence: MM. DD. YYYY.
{
yearDisplay.showNumberDecDot(100*honap+nap, true, 4, 0, 1); // push out the year
dateDisplay.showNumberDecDot(ev, false, 4, 0, 4); // push out the date
}
if (lang == 2 ) // German sequence: DD. MM. YYYY.
{
yearDisplay.showNumberDecDot(100*nap+honap, true, 4, 0, 1); // push out the year
dateDisplay.showNumberDecDot(ev, false, 4, 0, 4); // push out the date
}
}
}
if (SYS_STATE == 1) // Setting the alarm time
{
clockDisplay.clear();
clockDisplay.blinkRate(2);
AL_TIME = AL_HOUR*100 + AL_MIN;
if (AL_TIME == 0) // 0:00 alarm time
{
clockDisplay.writeDigitNum(1, 0);
clockDisplay.writeDigitNum(3, 0);
clockDisplay.writeDigitNum(4, 0);
} else
{
clockDisplay.print(AL_TIME,DEC); // Between 0:01 and 0:59 alarm time paddig the hour
if (AL_HOUR == 0)
{
clockDisplay.writeDigitNum(1, 0);
if (AL_MIN < 10) // Between 0:01 and 0:09 alarm time padding the minute too
{
clockDisplay.writeDigitNum(3, 0);
}
}
}
lux = lightMeter.readLightLevel(); // read the environment brightness
clockDisplay.setBrightness(int(lux/10)+bright_shift); // set clockdisplay brightness
// Now push out to the display the new values that were set above.
clockDisplay.writeDigitRaw(2, 0x02);
clockDisplay.writeDisplay();
yearDisplay.setBrightness(0); //set yeardisplay brightness to 0
dateDisplay.setBrightness(0); //set datedisplay brightness to 0
yearDisplay.showNumberDecDot(ev, false, 4, 0, 4); // push out the year
dateDisplay.showNumberDecDot(100*honap+nap, true, 4, 0, 1); // push out the date
}
}
void read()
{
if (irrecv.decode(&results)) //read the IR receiver
{
if (results.value == 0xFD708F) // >>| button pushed on remote
{
HOUR_OFFSET++; // hour offset increment
if (HOUR_OFFSET > 12)
{
HOUR_OFFSET = 12;
}
}
if (results.value == 0xFDB04F) // |<< button pushed on remote
{
HOUR_OFFSET--; // hour offset decrement
if (HOUR_OFFSET < -12)
{
HOUR_OFFSET = -12;
}
}
if (results.value == 0xFD20DF) // RPT button pushed on remote
{
HOUR_OFFSET = 2; // hour offset set to the default
}
if (results.value == 0xFD10EF) // EQ button pushed on remote
{
SYS_STATE = 1; // Clock is in the alarm setting mode
}
if (results.value == 0xFD40BF) // >|| button pushed on remote
{
if (SYS_STATE == 1)
{
SYS_STATE = 2; // Clock is running with alarm time
} else
{
if (SYS_STATE == 2)
{
SYS_STATE = 0; //Clock is running without alarm time, previous alarm time has deleted
AL_TIME = 0;
AL_HOUR = 0;
AL_MIN = 0;
}
}
}
if (results.value == 0xFD00FF) // Power button pushed on the remote
{
if (bright_shift == 2)
{
bright_shift = 0;
} else
{
bright_shift = 2;
}
}
if (results.value == 0xFD609F && SYS_STATE == 1) // CH+ button pushed on remote
{
AL_HOUR++; // Alarm hour increment
if (AL_HOUR > 23)
{
AL_HOUR = 0;
}
}
if (results.value == 0xFDA05F && SYS_STATE == 1) // CH- button pushed on remote
{
AL_HOUR--; // Alarm hour decrement
if (AL_HOUR < 0)
{
AL_HOUR = 23;
}
}
if (results.value == 0xFD50AF && SYS_STATE == 1) // VOL+ button pushed on remote
{
AL_MIN++; // Alarm minute increment
if (AL_MIN > 59)
{
AL_MIN = 0;
}
}
if (results.value == 0xFD906F && SYS_STATE == 1) // VOL- button pushed on remote
{
AL_MIN--; // Alarm minute decrement
if (AL_MIN < 0)
{
AL_MIN = 59;
}
}
if (results.value == 0xFD807F) // LANG button pushed on remote
{
lang++;
if (lang == 3)
{
lang = 0;
}
}
irrecv.resume(); // Receive the next value
}
}
Köszi előre is az agyazást, ha átrágjátok magatok rajta
