Thursday, April 26, 2012

Demo on SONY TV

http://www.youtube.com/watch?v=odO2gg5QSC4&feature=youtu.be

Final Project Code_Final (for SONY TV)


#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,13,10,9,8);
#include <IRremote.h>
IRsend irsend;

int buttonState1 = 1;
int buttonState2 = 1;
int buttonPin1 = 4;
int buttonPin2 = 6;
int power = 0;
int menuState = 0; //Channel Surf = 1, Channel input = 2, Volume = 3, Power = 4;
int displayState = 0; //Channel Surf = 1, Channel input = 2, Volume = 3, Power = 4;
int CS = 0; //Channel up = 1, Channel down = 2, Exit = 3
int CI = 0; //hundreds = 1, tens = 2, single = 3, Exit = 4
int hundreds = 0;
int tens = 0;
int ones = 0;
int Vol = 0; //Volume up = 1, Volume down = 2, Exit = 3
int channel = 0;
void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
}
void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  lcd.noAutoscroll();
  if (power == 1){
    //switch through main menu
    if(menuState == 0){
      if(displayState == 1){
        //LCD Displays Channel Surf Menu
        Serial.println("Go to Channel Surf Menu");
        //        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("To Channel Surf ");
      }
      if(displayState == 2){
        //LCD Displays Channel Input menu
        Serial.println("Go to Channel Input Menu");
        lcd.setCursor(0,0);
        lcd.print("To Channel Input");
      }
      if(displayState == 3){
        //LCD Displays Volume Menu
        Serial.println("Go to Volume Menu");
        lcd.setCursor(0,0);
        lcd.print("To Volume Menu  ");
      }
      if(displayState == 4){
        //LCD Displays Power Menu
        Serial.println("Go to Power Menu");
        lcd.setCursor(0,0);
        lcd.print("Turn Off        ");
      }
      if(buttonState2 == 0){
        displayState = displayState + 1;
        if(displayState == 5){
          displayState = 1;
        }
      }
    }
    //go into the menu (not just display)
    if(buttonState1 == 0){
      menuState = displayState;
    }
    //Channel Surf Menu
    if (menuState == 1){
      delay(100);
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      Serial.println("In Channel Surf Menu");
      lcd.setCursor(0,0);
      lcd.print("Channel Surf    ");
      if(buttonState2 == 0){
        CS = CS+1;
        if(CS == 4){
          CS = 1;
        }
        Serial.println(CS);
        if (CS == 1){
          lcd.setCursor(0,1);
          lcd.print("Channel Up      ");
        }
        if (CS == 2){
          lcd.setCursor(0,1);
          lcd.print("Channel Down    ");
        }
        if (CS == 3){
          lcd.setCursor(0,1);
          lcd.print("To Main Menu    ");
        }
      }
      if(CS == 1){
        if(buttonState1 == 0){
          Serial.println("transmit code to switch channel up");
          //transmit code to switch channel up
          for (int i = 0; i<3; i++){
            irsend.sendSony(0x90,12);
            delay(40);
          }
          delay(100);
          Serial.println("transmitted");
        }
      }
      if(CS == 2){
        if(buttonState1 == 0){
          Serial.println("transmit code to switch channel down");
          //transmit code to switch channel down
          for (int i = 0; i<3; i++){
            irsend.sendSony(0x890,12);
            delay(40);
          }
          delay(100);
          Serial.println("transmitted");
        }  
      }
      if(CS == 3){
        if(buttonState1 == 0){
          menuState = 0;
          lcd.clear();
          //goes back to main menu
          Serial.println("go back to main menu");
        }
      }
    }
    //Channel Input Menu
    if (menuState == 2){
      delay(100);
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      Serial.println("in channel input menu");
      lcd.setCursor(0,0);
      lcd.print("Channel Input   ");
      if(buttonState2 == 0){
        CI = CI + 1;
        if (CI == 6){
          CI = 1;
        }
        Serial.println(CI);
        //        if(CI == 1){
        //          //          lcd.setCursor(0,1);
        //          ////          lcd.print("                ");
        //          //          lcd.print("hundreds");
        //        }
        //        if(CI == 2){
        //          //          lcd.setCursor(0,1);
        //          ////          lcd.print("                ");
        //          //          lcd.print("tens");
        //        }
        //        if(CI == 3){
        //          //          lcd.setCursor(0,1);
        //          ////          lcd.print("                ");
        //          //          lcd.print("ones");
        //        }
                if(CI == 4){
                            lcd.setCursor(0,1);
                            lcd.print("Transmit Channel");
                }
                if(CI == 5){
                            lcd.setCursor(0,1);
                            lcd.print("To Main Menu    ");
                }
      }
      if(buttonState1 == 0){
         if(CI == 1){
          hundreds = hundreds + 1;
          if(hundreds == 10){
            hundreds = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 2){
          tens = tens + 1;
          if (tens == 10){
            tens = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 3){
          ones = ones + 1;
          if (ones == 10){
            ones = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 4){
          Serial.println("transmit input");
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print("Transmit Channel");
          //transmit code to input channel
         
          if(hundreds == 0){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x910,12);
              delay(40);
            }
          }
          if(hundreds == 1){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x10,12);
              delay(40);
            }
          }
          if(hundreds == 2){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x810,12);
              delay(40);
            }
          }
          if(hundreds == 3){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x410,12);
              delay(40);
            }
          }
          if(hundreds == 4){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xC10,12);
              delay(40);
            }
          }
          if(hundreds == 5){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x210,12);
              delay(40);
            }
          }
          if(hundreds == 6){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xA10,12);
              delay(40);
            }
          }
          if(hundreds == 7){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x610,12);
              delay(40);
            }
          }
          if(hundreds == 8){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xE10,12);
              delay(40);
            }
          }
          if(hundreds == 9){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x110,12);
              delay(40);
            }
          }
          delay(500);
          if(tens == 0){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x910,12);
              delay(40);
            }
          }
          if(tens == 1){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x10,12);
              delay(40);
            }
          }
          if(tens == 2){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x810,12);
              delay(40);
            }
          }
          if(tens == 3){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x410,12);
              delay(40);
            }
          }
          if(tens == 4){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xC10,12);
              delay(40);
            }
          }
          if(tens == 5){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x210,12);
              delay(40);
            }
          }
          if(tens == 6){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xA10,12);
              delay(40);
            }
          }
          if(tens == 7){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x610,12);
              delay(40);
            }
          }
          if(tens == 8){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xE10,12);
              delay(40);
            }
          }
          if(tens == 9){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x110,12);
              delay(40);
            }
          }
          if(ones == 0){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x910,12);
              delay(40);
            }
          }
          delay(500);
          if(ones == 1){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x10,12);
              delay(40);
            }
          }
          if(ones == 2){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x810,12);
              delay(40);
            }
          }
          if(ones == 3){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x410,12);
              delay(40);
            }
          }
          if(ones == 4){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xC10,12);
              delay(40);
            }
          }
          if(ones == 5){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x210,12);
              delay(40);
            }
          }
          if(ones == 6){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xA10,12);
              delay(40);
            }
          }
          if(ones == 7){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x610,12);
              delay(40);
            }
          }
          if(ones == 8){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0xE10,12);
              delay(40);
            }
          }
          if(ones == 9){
            for (int i = 0; i<3; i++){
              irsend.sendSony(0x110,12);
              delay(40);
            }
          }
//          ones = 0;
//          tens = 0;
//          hundreds = 0;

        }
        if(CI == 5){
          menuState = 0;
          Serial.println("back to main menu");
          lcd.clear();
          ones = 0;
          tens = 0;
          hundreds = 0;
        }
      }
      Serial.print(hundreds);
      Serial.print(tens);
      Serial.println(ones);
    }
    if (menuState == 3){
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      delay(50);
      Serial.println("in volume menu");
     
      lcd.setCursor(0,0);
      lcd.print("Volume          ");
      if(buttonState2 == 0){
        Vol = Vol+1;
        if(Vol == 4){
          Vol = 1;
        }
        Serial.println(Vol);
        if (Vol == 1){
          lcd.setCursor(0,1);
          lcd.print("Volume Up     ");
        }
        if (Vol == 2){
          lcd.setCursor(0,1);
          lcd.print("Volume Down   ");
        }
        if (Vol == 3){
          lcd.setCursor(0,1);
          lcd.print("To Main Menu    ");
        }
      }
      if(Vol == 1){
        if(buttonState1 == 0){
          //transmit code to switch volume up
          for (int i = 0; i<3; i++){
            irsend.sendSony(0x490,12);
            delay(40);
          }
          delay(100);
          Serial.println("transmitted");
          Serial.println("Transmit code to switch volume up");
        }
      }
      if(Vol == 2){
        if(buttonState1 == 0){
          //transmit code to switch volume down
          for (int i = 0; i<3; i++){
            irsend.sendSony(0xC90,12);
            delay(40);
          }
          delay(100);
          Serial.println("transmitted");
          Serial.println("Transmit code to switch volume down");
        }
      }
      if(Vol == 3){
        if(buttonState1 == 0){
          menuState = 0;
          lcd.clear();
          Serial.println("Back to main menu");
        }
      }
    }
    if (menuState == 4){
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      delay(50);
      if (buttonState1 == 0){
        //transmit code o switch TV off
        Serial.println("power off");
        lcd.clear();
        power = 0;
      }
      if (buttonState2 == 0){
        menuState = 0;
      }
      delay(50);
    }
  }
  if(power == 0){
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    if(buttonState1 == 0){
      power = 1;
    }
    else if(buttonState2 == 0){
      power = 1;
    }
    if(power == 1){
      //transmit code to turn power on
      for (int i = 0; i<3; i++){
        irsend.sendSony(0xA90,12);
        delay(20);
      }
      delay(100);
      Serial.println("transmitted");
//      for (int i = 0; i<3; i++){
//        irsend.sendSony(0xA90,12);
//        delay(40);
//      }
      Serial.println("power is on");
      lcd.print("Power ON");
      displayState = 1;
    }
  }
  if (buttonState1 + buttonState2 < 2){
    delay(200);
  }
  else{
    delay(100);
  }
}

TV remote decode

Power

A90
2704
Decoded SONY: A90 (12 bits)
Raw (26): -16132 2550 -400 1400 -400 850 -350 1350 -450 800 -400 1350 -450 750 -450 750 -400 1350 -450 750 -450 750 -450 750 -450 750


Channel Up
90
144
Decoded SONY: 90 (12 bits)
Raw (26): 4788 2600 -400 800 -400 800 -400 750 -450 750 -400 1350 -450 750 -450 750 -450 1350 -450 750 -450 700 -450 750 -450 750 


Channel Down
890
2192
Decoded SONY: 890 (12 bits)
Raw (26): -1452 2600 -400 1350 -450 750 -400 800 -400 800 -400 1350 -450 750 -450 750 -450 1300 -450 750 -450 750 -450 750 -450 750 


Volume Up
490
1168
Decoded SONY: 490 (12 bits)
Raw (26): -22532 2600 -350 850 -350 1400 -400 800 -400 800 -400 1350 -450 750 -450 750 -400 1350 -450 750 -450 750 -450 750 -450 700 


Volume Down
C90
3216


1

10
16



2

810
2064



3
410
1040


4
C10
3088


5
210
528


6
A10
2576


7
610
1552


8
E10
3600


9
110
272


0
910
2320


Thursday, April 19, 2012

Transmit code (test)


#include <IRremote.h>
IRsend irsend;
int pin = 3;

void setup(){
  Serial.begin(9600);
}
 

void loop(){
  pinMode(pin, OUTPUT);
  digitalWrite(pin, HIGH);
for (int i = 0; i<3; i++){
        irsend.sendSony(0x5422,15);
        delay(40);
      }
      delay(1000);
      Serial.println("transmitted");
}

IR decode


Power
5422
21538
Decoded SONY: 5422 (15 bits)
Raw (32): -21650 2550 -450 1350 -450 700 -500 1350 -450 700 -500 1300 -500 700 -500 700 -500 700 -500 700 -500 1300 -450 700 -500 700 -500 700 -500 1300 -500 700

1
26
38
Decoded SONY: 26 (15 bits)
Raw (32): 2978 2550 -500 700 -500 700 -500 750 -450 750 -450 750 -450 750 -500 700 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700

2
4026
16422
Decoded SONY: 4026 (15 bits)
Raw (32): -5176 2600 -450 1350 -450 750 -450 750 -450 750 -450 750 -450 750 -500 700 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700

3
2026
8230
Decoded SONY: 2026 (15 bits)
Raw (32): 28854 2550 -450 750 -450 1350 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 1300 -500 700 -500 750 -450 1300 -500 1300 -550 650

4
6026
24614
Decoded SONY: 6026 (15 bits)
Raw (32): 18992 2550 -450 1350 -500 1300 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 1300 -500 700 -550 650 -550 1250 -550 1300 -500 700

5
1026
4134
Decoded SONY: 1026 (15 bits)
Raw (32): -14820 2550 -450 750 -450 750 -500 1300 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 1300 -500 700 -550 650 -500 1300 -550 1250 -550 650

6
5026
20518
Decoded SONY: 5026 (15 bits)
Raw (32): 29882 2550 -450 1350 -500 700 -500 1300 -500 700 -500 700 -500 700 -500 700 -500 700 -500 700 -500 1300 -500 700 -550 650 -550 1250 -550 1250 -550 700

7
3026
12326
Decoded SONY: 3026 (15 bits)
Raw (32): 1392 2600 -450 750 -450 1350 -450 1350 -450 750 -450 750 -450 750 -450 750 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700

8
7026
28710
Decoded SONY: 7026 (15 bits)
Raw (32): 13552 2600 -450 1350 -450 1350 -450 1350 -450 750 -450 750 -450 750 -500 700 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700

9
826
2086
Decoded SONY: 826 (15 bits)
Raw (32): 7966 2550 -450 750 -450 750 -450 750 -450 1350 -500 700 -500 700 -500 700 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700

0
1826
6182
Decoded SONY: 1826 (15 bits)
Raw (32): -6432 2600 -400 800 -400 750 -500 1300 -500 1300 -500 700 -500 700 -500 700 -500 750 -450 750 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700


Channel Up
6726
26406
Decoded SONY: 6726 (15 bits)
Raw (32): -20114 2600 -450 1350 -450 1350 -450 700 -500 700 -550 1250 -550 1300 -500 1300 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 1300 -550 1250 -550 650

Channel Down
1726
5926
Decoded SONY: 1726 (15 bits)
Raw (32): 24324 2600 -450 750 -450 750 -450 1350 -450 700 -500 1350 -500 1250 -550 1250 -550 650 -550 700 -500 1300 -500 700 -500 700 -500 1300 -500 1300 -500 700


Volume Up
2422
9250
Decoded SONY: 2422 (15 bits)
Raw (32): 25508 2600 -400 800 -450 1350 -450 750 -450 750 -450 1350 -450 700 -500 700 -500 700 -500 700 -500 1350 -450 750 -450 750 -450 750 -500 1300 -500 700

Volume Down
6422
25634
Decoded SONY: 6422 (15 bits)
Raw (32): -15236 2550 -450 1350 -500 1300 -500 700 -500 700 -500 1300 -500 700 -500 700 -500 750 -450 750 -450 1350 -450 750 -500 700 -500 700 -500 1300 -500 700


4.19.2012 Final Project code


#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,13,10,9,8);
#include <IRremote.h>
IRsend irsend;

int buttonState1 = 1;
int buttonState2 = 1;
int buttonPin1 = 4;
int buttonPin2 = 6;
int power = 0;
int menuState = 0; //Channel Surf = 1, Channel input = 2, Volume = 3, Power = 4;
int displayState = 0; //Channel Surf = 1, Channel input = 2, Volume = 3, Power = 4;
int CS = 0; //Channel up = 1, Channel down = 2, Exit = 3
int CI = 0; //hundreds = 1, tens = 2, single = 3, Exit = 4
int hundreds = 0;
int tens = 0;
int ones = 0;
int Vol = 0; //Volume up = 1, Volume down = 2, Exit = 3
int channel = 0;
void setup(){
  Serial.begin(9600);
  lcd.begin(16,2);
}
void loop(){
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  lcd.noAutoscroll();
  if (power == 1){
    //switch through main menu
    if(menuState == 0){
      if(displayState == 1){
        //LCD Displays Channel Surf Menu
        Serial.println("Go to Channel Surf Menu");
        //        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("To Channel Surf ");
      }
      if(displayState == 2){
        //LCD Displays Channel Input menu
        Serial.println("Go to Channel Input Menu");
        lcd.setCursor(0,0);
        lcd.print("To Channel Input");
      }
      if(displayState == 3){
        //LCD Displays Volume Menu
        Serial.println("Go to Volume Menu");
        lcd.setCursor(0,0);
        lcd.print("To Volume Menu  ");
      }
      if(displayState == 4){
        //LCD Displays Power Menu
        Serial.println("Go to Power Menu");
        lcd.setCursor(0,0);
        lcd.print("Turn Off        ");
      }
      if(buttonState2 == 0){
        displayState = displayState + 1;
        if(displayState == 5){
          displayState = 1;
        }
      }
    }
    //go into the menu (not just display)
    if(buttonState1 == 0){
      menuState = displayState;
    }
    //Channel Surf Menu
    if (menuState == 1){
      delay(100);
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      Serial.println("In Channel Surf Menu");
      lcd.setCursor(0,0);
      lcd.print("Channel Surf    ");
      if(buttonState2 == 0){
        CS = CS+1;
        if(CS == 4){
          CS = 1;
        }
        Serial.println(CS);
        if (CS == 1){
          lcd.setCursor(0,1);
          lcd.print("Channel Up      ");
        }
        if (CS == 2){
          lcd.setCursor(0,1);
          lcd.print("Channel Down    ");
        }
        if (CS == 3){
          lcd.setCursor(0,1);
          lcd.print("To Main Menu    ");
        }
      }
      if(CS == 1){
        if(buttonState1 == 0){
          Serial.println("transmit code to switch channel up");
          //transmit code to switch channel up
          for (int i = 0; i<3; i++){
        irsend.sendSony(0x6726,15);
        delay(40);
      }
      delay(100);
      Serial.println("transmitted");
        }
      }
      if(CS == 2){
        if(buttonState1 == 0){
          Serial.println("transmit code to switch channel down");
          //transmit code to switch channel down
          for (int i = 0; i<3; i++){
        irsend.sendSony(0x1726,15);
        delay(40);
      }
      delay(100);
      Serial.println("transmitted");
        }  
      }
      if(CS == 3){
        if(buttonState1 == 0){
          menuState = 0;
          lcd.clear();
          //goes back to main menu
          Serial.println("go back to main menu");
        }
      }
    }
    //Channel Input Menu
    if (menuState == 2){
      delay(100);
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      Serial.println("in channel input menu");
      lcd.setCursor(0,0);
      lcd.print("Channel Input   ");
      if(buttonState2 == 0){
        CI = CI + 1;
        if (CI == 6){
          CI = 1;
        }
        Serial.println(CI);
        if(CI == 1){
          //          lcd.setCursor(0,1);
          ////          lcd.print("                ");
          //          lcd.print("hundreds");
        }
        if(CI == 2){
          //          lcd.setCursor(0,1);
          ////          lcd.print("                ");
          //          lcd.print("tens");
        }
        if(CI == 3){
          //          lcd.setCursor(0,1);
          ////          lcd.print("                ");
          //          lcd.print("ones");
        }
        if(CI == 4){
          //          lcd.setCursor(0,1);
          ////          lcd.print("                ");
          //          lcd.print("To Main Menu");
        }
      }
      if(buttonState1 == 0){
        if(CI == 1){
          hundreds = hundreds + 1;
          if(hundreds == 10){
            hundreds = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 2){
          tens = tens + 1;
          if (tens == 10){
            tens = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 3){
          ones = ones + 1;
          if (ones == 10){
            ones = 0;
          }
          channel = 100*hundreds + 10*tens + ones;
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print(channel);
        }
        if(CI == 4){
          Serial.println("transmit input");
          lcd.setCursor(0,1);
          //          lcd.print("                ");
          lcd.print("Transmit Channel");
          ones = 0;
          tens = 0;
          hundreds = 0;
        }
        if(CI == 5){
          menuState = 0;
          Serial.println("back to main menu");
          lcd.clear();
          ones = 0;
          tens = 0;
          hundreds = 0;
        }
      }
      Serial.print(hundreds);
      Serial.print(tens);
      Serial.println(ones);
    }
    if (menuState == 3){
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      delay(50);
      Serial.println("in volume menu");
      lcd.setCursor(0,0);
      lcd.print("Volume          ");
      if(buttonState2 == 0){
        Vol = Vol+1;
        if(Vol == 4){
          Vol = 1;
        }
        Serial.println(Vol);
        if (Vol == 1){
          lcd.setCursor(0,1);
          lcd.print("Volume Up     ");
        }
        if (Vol == 2){
          lcd.setCursor(0,1);
          lcd.print("Volume Down   ");
        }
        if (Vol == 3){
          lcd.setCursor(0,1);
          lcd.print("To Main Menu    ");
        }
      }
      if(Vol == 1){
        if(buttonState1 == 0){
          //transmit code to switch volume up
          for (int i = 0; i<3; i++){
        irsend.sendSony(0x2422,15);
        delay(40);
      }
      delay(100);
      Serial.println("transmitted");
          Serial.println("Transmit code to switch volume up");
        }
      }
      if(Vol == 2){
        if(buttonState1 == 0){
          //transmit code to switch volume down
          for (int i = 0; i<3; i++){
        irsend.sendSony(0x6422,15);
        delay(40);
      }
      delay(100);
      Serial.println("transmitted");
          Serial.println("Transmit code to switch volume down");
        }
      }
      if(Vol == 3){
        if(buttonState1 == 0){
          menuState = 0;
          lcd.clear();
          Serial.println("Back to main menu");
        }
      }
    }
    if (menuState == 4){
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);
      delay(50);
      if (buttonState1 == 0){
        //transmit code o switch TV off
        Serial.println("power off");
        lcd.clear();
        power = 0;
      }
      if (buttonState2 == 0){
        menuState = 0;
      }
      delay(50);
    }
  }
  if(power == 0){
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    if(buttonState1 == 0){
      power = 1;
    }
    else if(buttonState2 == 0){
      power = 1;
    }
    if(power == 1){
      //transmit code to turn power on
      for (int i = 0; i<3; i++){
        irsend.sendSony(0x5422,15);
        delay(40);
      }
      delay(100);
      Serial.println("transmitted");
      for (int i = 0; i<3; i++){
        irsend.sendSony(5422,15);
        delay(40);
      }
      Serial.println("power is on");
      lcd.print("Power ON");
      displayState = 1;
    }
  }
  if (buttonState1 + buttonState2 < 2){
    delay(200);
  }
  else{
    delay(100);
  }
}

Tuesday, April 17, 2012

Pictures: progression of our device

Before we attached the ability switches:










After we attached the ability switches (this is what the final prototype would look like):