#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,13,10,9,8);
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
void setup(){
Serial.begin(9600);
}
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.print("To Channel Surf ");
}
if(displayState == 2){
//LCD Displays Channel Input menu
Serial.println("Go to Channel Input Menu");
lcd.clear();
lcd.print("To Channel Input");
}
if(displayState == 3){
//LCD Displays Volume Menu
Serial.println("Go to Volume Menu");
lcd.clear();
lcd.print("To Volume Menu");
}
if(displayState == 4){
//LCD Displays Power Menu
Serial.println("Go to Power Menu");
lcd.clear();
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.clear();
lcd.print("Channel Surf");
if(buttonState2 == 0){
CS = CS+1;
if(CS == 4){
CS = 1;
}
Serial.println(CS);
}
if(buttonState1 == 0){
if(CS == 1){
//transmit code to switch channel up
Serial.println("transmit code to switch channel up");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("Channel Up");
}
if(CS == 2){
//transmit code to switch channel down
Serial.println("transmit code to swithc channel down");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("Channel Down");
}
if(CS == 3){
menuState = 0;
//goes back to main menu
Serial.println("go back to main menu");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("To Main Menu");
}
}
}
//Channel Input Menu
if (menuState == 2){
delay(100);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
Serial.println("in channel input menu");
if(buttonState2 == 0){
CI = CI + 1;
if (CI == 5){
CI = 1;
}
Serial.println(CI);
}
if(buttonState1 == 0){
if(CI == 1){
hundreds = hundreds + 1;
if(hundreds == 10){
hundreds = 0;
}
}
if(CI == 2){
tens = tens + 1;
if (tens == 10){
tens = 0;
}
}
if(CI == 3){
ones = ones + 1;
if (ones == 10){
ones = 0;
}
}
if(CI == 4){
menuState = 0;
Serial.println("back to main menu");
}
}
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");
if(buttonState2 == 0){
Vol = Vol+1;
if(Vol == 4){
Vol = 1;
}
Serial.println(Vol);
}
if(buttonState1 == 0){
if(Vol == 1){
//transmit code to switch volume up
Serial.println("Transmit code to switch volume up");
}
if(Vol == 2){
//transmit code to switch volume down
Serial.println("Transmit code to switch volume down");
}
if(Vol == 3){
menuState = 0;
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.noDisplay();
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
Serial.println("power is on");
lcd.print("Power ON");
displayState = 1;
}
}
if (buttonState1 + buttonState2 < 2){
delay(1000);
}
else{
delay(100);
}
}
LiquidCrystal lcd(12,11,13,10,9,8);
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
void setup(){
Serial.begin(9600);
}
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.print("To Channel Surf ");
}
if(displayState == 2){
//LCD Displays Channel Input menu
Serial.println("Go to Channel Input Menu");
lcd.clear();
lcd.print("To Channel Input");
}
if(displayState == 3){
//LCD Displays Volume Menu
Serial.println("Go to Volume Menu");
lcd.clear();
lcd.print("To Volume Menu");
}
if(displayState == 4){
//LCD Displays Power Menu
Serial.println("Go to Power Menu");
lcd.clear();
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.clear();
lcd.print("Channel Surf");
if(buttonState2 == 0){
CS = CS+1;
if(CS == 4){
CS = 1;
}
Serial.println(CS);
}
if(buttonState1 == 0){
if(CS == 1){
//transmit code to switch channel up
Serial.println("transmit code to switch channel up");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("Channel Up");
}
if(CS == 2){
//transmit code to switch channel down
Serial.println("transmit code to swithc channel down");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("Channel Down");
}
if(CS == 3){
menuState = 0;
//goes back to main menu
Serial.println("go back to main menu");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print("To Main Menu");
}
}
}
//Channel Input Menu
if (menuState == 2){
delay(100);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
Serial.println("in channel input menu");
if(buttonState2 == 0){
CI = CI + 1;
if (CI == 5){
CI = 1;
}
Serial.println(CI);
}
if(buttonState1 == 0){
if(CI == 1){
hundreds = hundreds + 1;
if(hundreds == 10){
hundreds = 0;
}
}
if(CI == 2){
tens = tens + 1;
if (tens == 10){
tens = 0;
}
}
if(CI == 3){
ones = ones + 1;
if (ones == 10){
ones = 0;
}
}
if(CI == 4){
menuState = 0;
Serial.println("back to main menu");
}
}
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");
if(buttonState2 == 0){
Vol = Vol+1;
if(Vol == 4){
Vol = 1;
}
Serial.println(Vol);
}
if(buttonState1 == 0){
if(Vol == 1){
//transmit code to switch volume up
Serial.println("Transmit code to switch volume up");
}
if(Vol == 2){
//transmit code to switch volume down
Serial.println("Transmit code to switch volume down");
}
if(Vol == 3){
menuState = 0;
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.noDisplay();
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
Serial.println("power is on");
lcd.print("Power ON");
displayState = 1;
}
}
if (buttonState1 + buttonState2 < 2){
delay(1000);
}
else{
delay(100);
}
}
No comments:
Post a Comment