-/*
-A4, A5 - I2C
-
-A2 - SETUP / IN
-A0 - ENTER / IN
-D12 - DOWN / IN
-D11 - UP / IN
-D10 - IR / IN
-D9 - BUZZER /OUT
-D4 - TEMP(DS18B20) /IN
-D3 - IR / OUT
-D2 - PIR /IN
-*/
-
-
-
 
 #include <Wire.h>
 #include <OneWire.h>

void setup()
{

  // lcd
  lcd.init();
  lcd.backlight();
  lcd.clear();
  lcd.createChar(1, termometru);
  lcd.setCursor(0, 0);
  lcd.write(1);
  // lcd

  Serial.begin (38400);
  Serial.println("TV controller Starting");
  delay(20);

  irrecv.enableIRIn(); // Start the receiver

  startMills = millis();

  // pin mode

  pinMode(SETUP_IN_PIN, INPUT_PULLUP);
  pinMode(ENTER_IN_PIN, INPUT_PULLUP);
  pinMode(DN_IN_PIN, INPUT_PULLUP);
  pinMode(UP_IN_PIN, INPUT_PULLUP);
  pinMode(PIR_IN_PIN, INPUT_PULLUP);

  pinMode(BZ_OU_PIN, OUTPUT);
  digitalWrite(BZ_OU_PIN, HIGH);


  // temp
  sensors.begin();
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
  sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION);

#include <LiquidCrystal_I2C.h>
#include <IRremote.h>

// eeprom
#include <avr/eeprom.h>
#define eeprom_read_to(dst_p, eeprom_field, dst_size) eeprom_read_block(dst_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(dst_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_read(dst, eeprom_field) eeprom_read_to(&dst, eeprom_field, sizeof(dst))
#define eeprom_write_from(src_p, eeprom_field, src_size) eeprom_write_block(src_p, (void *)offsetof(__eeprom_data, eeprom_field), MIN(src_size, sizeof((__eeprom_data*)0)->eeprom_field))
#define eeprom_write(src, eeprom_field) { typeof(src) x = src; eeprom_write_from(&x, eeprom_field, sizeof(x)); }

// Change this any time the EEPROM content changes
const long magic_number = 0x0326;
 
struct __eeprom_data {
  long magic;
  boolean pwrSrc;     // True : connected to TV, False : usb powered
  boolean wrkMode;    // True : thermostat + TV, False : thermostat
  boolean startMode;  // if wrkMode == True, True : run TV on/off or channel change, False : do nothing indicating a sign on the lcd
  boolean beepMode;   // True : beep on
  boolean offMode;    // True : TV on/off, False : channel change
  int channelGap;     // 1 ~ 5
  int tvOnTime;       // 30 ~ 120
  int tvOffTime;      // 5 ~ 20
};

//
int SETUP_IN_PIN = A2;
int WRK_MODE_IN_PIN = A0;
/*
int UP_IN_PIN    = 12;
int DN_IN_PIN    = 11;
*/

int IR_IN_PIN    = 10;
int PIR_IN_PIN   = 2;
int BZ_OU_PIN    = 9;

// LCD
LiquidCrystal_I2C lcd(0x27, 20, 4);
