Stigern.Net


LCD Menu

All Arduino talk goes here

LCD Menu

Postby doubravacek » 17 Jan 2010 20:46

Hi,

is possible to obtain your arduino sketch for LCD menu, please? I the one but not so good like yours. :-)

David
doubravacek
 
Posts: 1
Joined: 17 Jan 2010 20:42

Re: LCD Menu

Postby Stigern » 22 Jan 2010 16:51

doubravacek wrote:Hi,

is possible to obtain your arduino sketch for LCD menu, please? I the one but not so good like yours. :-)

David


I think this is the one you want:
Code: Select all
#include <NewSoftSerial.h>
#include <MegaServo.h>
#define BANDGAPREF 14
//////////////////////////////////////////////
MegaServo myservo;
NewSoftSerial mySerial(7, 8);
const byte  buttonPin = 9;
const byte  buttonPin2 = 10;
const byte  buttonPin3 = 11;
const byte  buttonPin4 = 12;
byte updateit = 10;
byte menu = 0;
byte ledon = 0;
int voltage = 0;
int scrolling = 0;
int sysdelay = 10;
int count = 0;
int resolution = 1;
int tempdel = 80;
byte relay = 7;
byte lang = 0;
float temperatureC = 0;
/////////////////////////////////////////////
byte buttonState = 0;         
byte lastButtonState = 0;
/////////////////////////////////////////////
byte buttonState2 = 0;         
byte lastButtonState2 = 0;
/////////////////////////////////////////////
byte buttonState3 = 0;         
byte lastButtonState3 = 0;
/////////////////////////////////////////////
byte buttonState4 = 0;         
byte lastButtonState4 = 0;
/////////////////////////////////////////////
void setup() 
{
  // set the data rate for the NewSoftSerial port
  mySerial.begin(9600);
  // Set all buttonpins as inputs
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  // Set output for led on pin 13
  pinMode(13, OUTPUT);
  pinMode(relay, OUTPUT);
  // Attach the servo!
  myservo.attach(3);

}

void loop()                   
{
  // Run trough the buttons!
  Button1(); // Menu choose up
  Button2(); // Adjust up
  Button3(); // Adjust down
  Button4(); // Menu choose down

  // Other Stuff
  UpdateLCD();
  delay(sysdelay);
  scrolling++;
  if (scrolling == 710)
    scrolling = 0;

  if (menu == 7 && scrolling == 1)
    updateit++;
  if (menu == 7 && scrolling == 251)
    updateit++;
  if (menu == 7 && scrolling == 401)
    updateit++;
  if (menu == 6 && scrolling == 10)
    updateit++;
  if (menu == 6 && scrolling == 300)
    updateit++;
  if (menu == 6 && scrolling == 680)
    updateit++;


ReadTemperature();


}

void UpdateServo()
{
  myservo.write(count);
}
void Button1()
{
  buttonState = digitalRead(buttonPin);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {

      // if the current state is HIGH then the button
      // wend from off to on:

      if (menu < 9)
        menu++;
    }
    lastButtonState = buttonState;
    updateit++;
  }
}

void Button2()
{
  buttonState2 = digitalRead(buttonPin2);
  // compare the buttonState to its previous state
  if (buttonState2 != lastButtonState2) {
    // if the state has changed, increment the counter
    if (buttonState2 == HIGH) {
      UpdateServo();
      // if the current state is HIGH then the button
      // wend from off to on:
      if (menu == 0)
      {
        digitalWrite(13, HIGH);
      }

      if (menu == 4)
      {
        digitalWrite(relay, HIGH);
      }

      if (menu == 1)
      {
        if ((count + resolution) < 181)
        {
          count += resolution;
        }
      }

      if (menu == 2)
      {
        if (resolution < 15)
        {
          resolution++;
        }
      }

      if (menu == 5)
      {
        if (tempdel < 200)
        {
          tempdel++;
        }
      }
      if (menu == 3)
      {
        if (sysdelay < 250)
        {
          sysdelay += 10;
        }
      }

      if (menu == 8)
      {
        lang = 0;
      }
      updateit++;
    }
    lastButtonState2 = buttonState2;
  }
}

void Button3()
{
  buttonState3 = digitalRead(buttonPin3);
  // compare the buttonState to its previous state
  if (buttonState3 != lastButtonState3) {
    // if the state has changed, increment the counter
    if (buttonState3 == HIGH) {
      UpdateServo();
      // if the current state is HIGH then the button
      // wend from off to on:

      if (menu == 0)
      {
        digitalWrite(13, LOW);
      }
      if (menu == 4)
      {
        digitalWrite(relay, LOW);
      }
      if (menu == 1)
      {
        if (count >= resolution)
        {
          count -= resolution;
        }
      }

      if (menu == 2)
      {
        if (resolution > 1)
        {
          resolution--;
        }
      }

      if (menu == 5)
      {
        if (tempdel > 50)
        {
          tempdel--;
        }
      }
      if (menu == 3)
      {
        if (sysdelay > 11)
        {
          sysdelay -= 10;
        }
        else
        {
          sysdelay = 1;
        }
      }

      if (menu == 8)
      {
        lang = 1;
      }

      updateit++;
    }
    lastButtonState3 = buttonState3;
  }
}

void Button4()
{
  buttonState4 = digitalRead(buttonPin4);
  // compare the buttonState to its previous state
  if (buttonState4 != lastButtonState4) {
    // if the state has changed, increment the counter
    if (buttonState4 == HIGH)
    {
      // if the current state is HIGH then the button
      // wend from off to on:
      if (menu > 0)
        menu--;
    }
    lastButtonState4 = buttonState4;
    updateit++;
  }
}

void UpdateLCD()
{
  if (updateit > 0)
  {
    if (menu == 0)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("   LED Pin 13");
      if (lang == 1)
        mySerial.print(" LED Pinne 13");
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- On/Off ->");
      if (lang == 1)
        mySerial.print("  <- Paa/Av ->");
      updateit--;
    }
    if (menu == 1)
    {
      clearLCD();
      firstrow();
      mySerial.print(" Servo: ");
      mySerial.print(count);
      if (lang == 0)
        mySerial.print(" deg.");
      if (lang == 1)
        mySerial.print(" gra.");
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- Adjust ->");
      if (lang == 1)
        mySerial.print("  <- Juster ->");
      updateit--;
    }
    if (menu == 2)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("  Servo Res: ");
      if (lang == 1)
        mySerial.print("  Servo Opp: ");
      mySerial.print(resolution);
      secndtrow();
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- Adjust ->");
      if (lang == 1)
        mySerial.print("  <- Juster ->");
      updateit--;
    }
    if (menu == 3)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print(" Sys Delay: ");
      if (lang == 1)
        mySerial.print("Sys Treghet: ");
      mySerial.print(sysdelay);
      secndtrow();
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- Adjust ->");
      if (lang == 1)
        mySerial.print("  <- Juster ->");
      updateit--;
    }

    if (menu == 4)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("  Servo Power");
      if (lang == 1)
        mySerial.print("Servo Aktivert");
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- On/Off ->");
      if (lang == 1)
        mySerial.print("  <- Paa/Av ->");
      updateit--;
    }

    if (menu == 5)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print(" Temp Cor: ");
      if (lang == 1)
        mySerial.print(" Temp Kor: ");
      mySerial.print(tempdel);
      secndtrow();
      secndtrow();
      if (lang == 0)
        mySerial.print("  <- Adjust ->");
      if (lang == 1)
        mySerial.print("  <- Juster ->");
      updateit--;
    }

    if (menu == 6)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("  Temperature");
      if (lang == 1)
        mySerial.print("   Temperatur");
      secndtrow();
      mySerial.print("    ");
      mySerial.print(temperatureC);
      mySerial.print(" C");
      updateit--;
    }

    if (menu == 7)
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("Firmware Version");
      if (lang == 1)
        mySerial.print(" System Versjon");
      secndtrow();
      if (scrolling > 0 && scrolling < 250)
      {
        mySerial.print("  Beta (0.43)");
      }
      if (scrolling > 250 && scrolling < 400)
      {
        if (lang == 0)
          mySerial.print("   By Stigern");
        if (lang == 1)
          mySerial.print("   Av Stigern");
      }
      if (scrolling > 400 && scrolling < 700)
      {
        mySerial.print("Www.Stigern.Net");
      }
      updateit--;
    }

    if (menu == 8) ///// Language Selection
    {
      clearLCD();
      firstrow();
      if (lang == 0)
        mySerial.print("Sel Language");
      if (lang == 1)
        mySerial.print("Velg Spraak");
      secndtrow();
      if (lang == 0)
        mySerial.print("[English]");
      if (lang == 1)
        mySerial.print("[Norsk]");
      updateit--;
    }
  }
}

/////////////////////////////////////////////////
void clearLCD()
{
  mySerial.print(0xFE, BYTE); //command flag
  mySerial.print(0x01, BYTE); //clear command. //
}
/////////////////////////////////////////////////////

void firstrow()
{
  mySerial.print(0xFE, BYTE);
  mySerial.print(0x03, BYTE);
  delay(2);
}
//////////////////////////////////////////////
void secndtrow()
{
  mySerial.print(254, BYTE);
  mySerial.print(192, BYTE);
  delay(2);
}
//////////////////////////////////////////////

void ReadTemperature()
{
    // Read temp
// get voltage reading from the secret internal 1.05V reference
  int refReading = analogRead(BANDGAPREF); 
 
  // now calculate our power supply voltage from the known 1.05 volt reading
  float supplyvoltage = (1.05 * 1024) / refReading;
 
  //getting the voltage reading from the temperature sensor
  int reading = analogRead(0); 

  // converting that reading to voltage
  float voltage = reading * supplyvoltage / 1024;

  temperatureC = (voltage - 0.5) * tempdel ;
}



















<3 C# & Arduino
User avatar
Stigern
Forum Admin
 
Posts: 41
Joined: 22 Nov 2007 06:30
Location: Norway


Return to Arduino

Who is online

Users browsing this forum: No registered users and 0 guests

cron