Show Posts
Pages: 1 2 [3] 4 5 ... 8
31  Using Arduino / Programming Questions / Does this look right. on: May 23, 2013, 02:05:02 pm
Is BUTTON 1 just a term or is it on Pin 1 and not on pin 3 in this statement.

Code:
#define BUTTONR 2 // Intr 0 = Pin 2 encoder push button
#define BUTTON 1 // Intr 1 = Pin 3
32  Using Arduino / Programming Questions / Re: Programming for encoder connected to Arduino Pro Mini +3.3V 8Mhz on: May 23, 2013, 01:34:14 am
is the "auto scroll" and "newline" selected on serial monitor.
33  Using Arduino / Programming Questions / Re: whats happening here. on: May 22, 2013, 04:38:18 pm
Quote
whats about the if(moved) statement.... I do not see the variable defined.

boolean moved = false; appears earlier in the sketch. but not in the parts shown here.
34  Community / Website and Forum / Re: karma on: May 22, 2013, 03:11:31 pm
Thanks, don't think mines working can you click it to see if it works, ha.
35  Using Arduino / Programming Questions / Re: Replacing buttons with a keypad on: May 22, 2013, 03:09:00 pm
Instead of doing posts with a fraction of the program, attach the whole file. At the bottom when you write your post, "Additional options" ...
Then we can see the problem.
36  Community / Website and Forum / karma on: May 22, 2013, 03:03:01 pm
How do you earn karma.
37  Using Arduino / Programming Questions / Re: Programming for encoder connected to Arduino Pro Mini +3.3V 8Mhz on: May 22, 2013, 02:32:32 pm
Quote
Serial.begin(115200);

Have you also checked that serial monitor is set to  115200.
38  Using Arduino / Programming Questions / Re: whats happening here. on: May 22, 2013, 02:09:53 pm
thanks, that helped. karma awarded smiley-grin I should have posted this code but your answer still fits.  Interestingly, I cant see why I get to "Change Units    " select it but dont get to settingsChangeUnits();

Which is the code above.

Code:
void displayMenu() {
  int selected = 3;

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Turn the knob to");
  lcd.setCursor(0,1);
  lcd.print("select an option");
  // display options
  while (!buttonR.wasPressed()) {
    selected += readEncoder();// selected = encoder
    if (selected<0) selected=3;
    if (selected>3) selected=0;
    if (moved) {
      lcd.clear();
      lcd.setCursor(0,0);
      switch(selected) {
      case 0:
        lcd.print("Change Units    ");
        break;
      case 1:
        lcd.print("Backlight On/Off");
        break;
      case 2:
        lcd.print("Logging On/Off  ");
        break;
      case 3:
        lcd.print("Exit Settings   ");
        break;
      }
    }
  }
  // when button is pressed...
  //lcd.clear();
  switch(selected) {
  case 0:
    settingsChangeUnits();
    break;
  case 1:
    //settingsChangeBacklight();
    break;
  case 2:
    break;
  }
}
39  Using Arduino / Programming Questions / whats happening here. on: May 22, 2013, 01:55:22 pm
can someone explain (breakdown)what is happening in this code.

Code:
void settingsChangeUnits() {
  int selected = 2;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Select Unit     ");
  lcd.setCursor(0,1);
  lcd.print("Currently it's ");
  while (!buttonR.wasPressed()) {
    selected += readEncoder();
    if (selected<0) selected=2;
    if (selected>2) selected=0;
    if (moved) {
      lcd.setCursor(0,1);
      switch(selected) {
      case 0:
        lcd.print("Celcius         ");
        break;
      case 1:
        lcd.print("Fahrenheit      ");
        break;
      case 2:
        lcd.print("Cancel          ");
        break;
      }
    }
  }
  // when button is pressed...
  switch(selected) {
  case 0:
    lcd.print ("C");
    break;
  case 1:
    lcd.print ("F");
    break;
  }
}

And can you have a switch statement that relates to the first switch statement which I think is happening here. smiley-roll-blue
40  Using Arduino / Programming Questions / advice needed on: May 21, 2013, 08:08:34 am
From power up the LCD shows Time and Date

I can navigate the menu but seem to be always stuck in case 1: or case 2: I cant seem to change the Rtc parameters as I just get put back into the menu.

Code:
void loop()
{
  if (menuRoot == true)
  {
    lcd.setCursor(4, 0);
    lcd.print(rtc.formatTime());
    lcd.setCursor(3, 1);
    lcd.print(rtc.formatDate());

I then navigate the menus using the encoder

Code:
void readEncoder() //read the encoder and set lastButtonPushed to values used by navigateMenu()
{
  n = digitalRead(encoder0PinA);// n is current state of encoder0PinA pin
  if ((encoder0PinALast == HIGH) && (n == LOW)) // check if encoder0PinA pin has changed state
  {
    if (digitalRead(encoder0PinB) == LOW)
    {
      lastButtonPushed = 1; //if it has changed and its now low decrement  encoder0Pos;
    }
    else
    {
      lastButtonPushed = 2; // if it has changed and its now high, increment encoder0Pos
    }
  }
  encoder0PinALast = n; // set the variable holding the previous state to the value n read above
}

Then using case 1; or case 2 of the void navigateMenus, I move Left/Right through the menu till I get to for example "Min" from void menuChanged.

Code:
void menuChanged(MenuChangeEvent changed){

  MenuItem newMenuItem=changed.to; //get the destination menu

  lcd.setCursor(0,0); //set the start position for lcd printing to the second row

  if(newMenuItem.getName()==menu.getRoot()){
    lcd.clear();
    menuRoot = true;    
  }
  //MENU SET CLOCK
  else if(newMenuItem.getName()=="menuSetClock"){
    menuRoot = false;
    lcd.clear();
    lcd.print("Set Clock");
  }
  else if(newMenuItem.getName()=="menuItemHr"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Hr");
  }
  else if(newMenuItem.getName()=="menuItemMin"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Min");
  }
}

 Now that I have "Min" displayed on the LCD. I select it by pressing the encoder push button on pin 45.

Code:
void menuUsed(MenuUseEvent used){ //                  **if you have a function call it here**
  if ( used.item == menuItemHr ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeHour();
  }
  else if ( used.item == menuItemMin ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeMin();
  }

  if ( used.item == menuExit ){
    menu.toRoot();//etc.
  }
}

This now shows the LCD displaying the clock. because of the function changeMin() called from void menuUsed above

Code:
void changeMin(){

  //min=rtc.getMinute();
  if(digitalRead(encoderPushButton) == HIGH)
  {
    min = ++min % 60; //  this is better than // min += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) min = ++min % 60 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) min = (--min + 60) % 60 // decrement and rollunder past 0
  }
  rtc.setTime(hour, min,sec);
}

At this point If I use the encoder case 1 or case 2, it does not change the Mins on the clock. It simply navigates the menu left or right.

but if I press the encoder push button, the minutes change... hope this helps


41  Using Arduino / Programming Questions / Re: Some issue with Adruino Mini Pro and a SIM900 module on: May 19, 2013, 04:22:45 pm

Quote
Trying to force the baud-rate to 9600

using a pass through sketch you can use Serial monitor to send commands to the gsm module and get feedback from the gsm module to see what settings it uses. But you get more info
if you can use Terminal services. The link i sent you has a pass through sketch to do this. Not sure how you arduino board will work with it, you might have to edit some pins ect.

You should have a manual for the Gsm with the relevant AT commands you issue to the gsm module to find the relevant info.
42  Using Arduino / Programming Questions / Re: For loop on: May 19, 2013, 04:15:14 pm
I prefer apples at least it answered my question. smiley-wink
43  Using Arduino / Programming Questions / Re: Some issue with Adruino Mini Pro and a SIM900 module on: May 19, 2013, 03:25:30 pm
what is the baud rate that the gsm is set to.
have your tried a pass through sketch

look at this

http://tronixstuff.wordpress.com/tag/sm5100/

different setup but it might shed some light
44  Using Arduino / Programming Questions / multi-menu 1 encoder on: May 19, 2013, 12:50:51 pm
I can navigate the menu but seem to be always stuck in case 1: or case 2: I cant seem to change the Rtc parameters as I just get put back into the menu.

what am i missing in my code.

Code:
#include <Wire.h>
#include <Rtc_Pcf8563.h>
#include <MenuBackend.h> //MenuBackend library - copyright by Alexander Brevig
#include <LiquidCrystal.h> //this library is included in the Arduino IDE

const int encoderPushButton = 45; // pin for the Enter button
const int buttonPinEsc = 42; // pin for the Esc button

int encoder0PinA = 2;
int encoder0PinB = 3;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int n = HIGH;

int menuRoot = true;// A global flag. true = root (top) menu and display clock. false = don't display clock

int lastButtonPushed = 0;
int lastButtonEnterState = LOW; // the previous reading from the Enter input pin
int lastButtonEscState = LOW; // the previous reading from the Esc input pin
long lastEnterDebounceTime = 0; // the last time the output pin was toggled
long lastEscDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 150; // the debounce time

LiquidCrystal lcd(7,8,9,10,11,12);

Rtc_Pcf8563 rtc;//init the real time clock

// Time and Date

byte sec;
byte min;
byte hour;
byte day;
byte weekday;
byte month;
byte year;
byte century;

//Menu variables i.e. whats in the menu
MenuBackend menu = MenuBackend(menuUsed,menuChanged);

//initialize menuitems
MenuItem menuSetClock = MenuItem("menuSetClock"); // 2nd menu item
MenuItem menuItemHr = MenuItem("menuItemHr"); // sub menu
MenuItem menuItemMin = MenuItem("menuItemMin"); //sub menu
MenuItem menuExit = MenuItem("menuExit"); // 6th menu item



void setup()
{
  lcd.begin(16, 2);
  pinMode(encoderPushButton, INPUT);
  pinMode(buttonPinEsc, INPUT);
  pinMode (encoder0PinA,INPUT);
  pinMode (encoder0PinB,INPUT);



  //How the menu will look.
  lcd.setCursor(0,0);
  menu.getRoot().addRight(menuSetClock); // set main menu items
  menuSetClock.add(menuItemHr).addRight(menuItemMin); // add first sub menu then addright additional sub menues for that menu
  menuExit.add(menuExit);
  menu.toRoot();
}



void loop()
{
  if (menuRoot == true)
  {
    lcd.setCursor(4, 0);
    lcd.print(rtc.formatTime());
    lcd.setCursor(3, 1);
    lcd.print(rtc.formatDate());

  }
  readButtons(); //I splitted button reading and navigation in two procedures because
  readEncoder();
  navigateMenus(); //in some situations I want to use the button for other purpose (eg. to change some settings)
  {
  }
}


void  readButtons() //read buttons status

  int reading;
  int buttonEnterState=LOW; // the current reading from the Enter input pin
  int buttonEscState=LOW; // the current reading from the input pin


  //ENTER BUTTON DEBOUNCE

  reading = digitalRead(encoderPushButton); // read the state of the switch into a local variable:

  if (reading != lastButtonEnterState) // If the switch changed, due to noise or pressing:
  {
    lastEnterDebounceTime = millis(); // reset the debouncing timer
  }
  if ((millis() - lastEnterDebounceTime) > debounceDelay) // whatever the reading is at, it's been there for longerthan the debounce delay, so take it as the actual current state:
  {         
    buttonEnterState=reading;
    lastEnterDebounceTime=millis();
  }
  lastButtonEnterState = reading; // save the reading.  Next time through the loop, it'll be the lastButtonState:


  //ESC BUTTON DEBOUNCE           

  reading = digitalRead(buttonPinEsc); // read the state of the switch into a local variable:

  if (reading != lastButtonEscState) // If the switch changed, due to noise or pressing:
  {
    lastEscDebounceTime = millis(); // reset the debouncing timer
  }
  if ((millis() - lastEscDebounceTime) > debounceDelay)// whatever the reading is at, it's been there for longerthan the debounce delay, so take it as the actual current state:
  {
    buttonEscState = reading;
    lastEscDebounceTime=millis();
  }
  lastButtonEscState = reading; // save the reading.  Next time through the loop, it'll be the lastButtonState:

  //Records which button has been pressed
  if (buttonEnterState==HIGH){
    lastButtonPushed=encoderPushButton;
  }
  else if(buttonEscState==HIGH){
    lastButtonPushed=buttonPinEsc;
  }
  else{
    lastButtonPushed=0;
  }                 
}


void readEncoder() //read the encoder and set lastButtonPushed to values used by navigateMenu()
{
  n = digitalRead(encoder0PinA);// n is current state of encoder0PinA pin
  if ((encoder0PinALast == HIGH) && (n == LOW)) // check if encoder0PinA pin has changed state
  {
    if (digitalRead(encoder0PinB) == LOW)
    {
      lastButtonPushed = 1; //if it has changed and its now low decrement  encoder0Pos;
    }
    else
    {
      lastButtonPushed = 2; // if it has changed and its now high, increment encoder0Pos
    }
  }
  encoder0PinALast = n; // set the variable holding the previous state to the value n read above
}


void menuChanged(MenuChangeEvent changed){

  MenuItem newMenuItem=changed.to; //get the destination menu

  lcd.setCursor(0,0); //set the start position for lcd printing to the second row

  if(newMenuItem.getName()==menu.getRoot()){
    lcd.clear();
    menuRoot = true;   
  }
  //MENU SET CLOCK
  else if(newMenuItem.getName()=="menuSetClock"){
    menuRoot = false;
    lcd.clear();
    lcd.print("Set Clock");
  }
  else if(newMenuItem.getName()=="menuItemHr"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Hr");
  }
  else if(newMenuItem.getName()=="menuItemMin"){
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("Min");
  }
}


void menuUsed(MenuUseEvent used){ //                  **if you have a function call it here**
  if ( used.item == menuItemHr ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeHour();
  }
  else if ( used.item == menuItemMin ){
    lcd.clear();//etc.
    lcd.setCursor(0, 0);
    lcd.print(rtc.formatTime());
    changeMin();
  }

  if ( used.item == menuExit ){
    menu.toRoot();//etc.
  }
}


void navigateMenus()
{
  MenuItem currentMenu=menu.getCurrent();

  switch (lastButtonPushed)
  {
  case encoderPushButton: // enter pin
    if(!(currentMenu.moveDown()))//if the current menu has a child and enter has been pressed  then navigate menu to item below
    { 
      menu.use();
    }
    else //otherwise, if menu has no child and enter has been pressed---- the current menu is used
    {
      menu.moveDown();
    }
    break;
  case buttonPinEsc:
    lcd.clear();
    menu.toRoot();  //back to main
    break;
  case 1: //Encoder right/buttonPinRight --:
    menu.moveRight();

    break;     
  case 2: //Encoder left/buttonPinLeft ++:
    menu.moveLeft();
    break;     
  }
  lastButtonPushed=0; //reset the lastButtonPushed variable
}


void changeMin(){

  //min=rtc.getMinute();
  if(digitalRead(encoderPushButton) == HIGH)
  {
    min = ++min % 60; //  this is better than // min += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) min = ++min % 60 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) min = (--min + 60) % 60 // decrement and rollunder past 0
  }
  rtc.setTime(hour, min,sec);
}

void changeHour(){

  // hour=rtc.getHour();

  if(digitalRead(encoderPushButton) == HIGH)
  {
    hour = ++hour % 24; //  this is better than // hour += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) hour = ++hour % 60 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) hour = (--hour + 60) % 60 // decrement and rollunder past 0
  }
  rtc.setTime(hour, min,sec);
  rtc.setTime(sec, min, hour);
}


void changeDay(){

  // Yet to be done
  if(digitalRead(encoderPushButton) == HIGH)
  {
    day = ++day % 32; //  this is better than // day += 1;as it rolls overfrom 59 to 00
    //if (incrementMinuteButtonPressDectected) dayn = ++day % 31 // increment and rollover past 59
    //if (decrementMinuteButtonPressDectected) day = (--day + 31) % 31 // decrement and rollunder past 0
  }
  rtc.setDate(day,weekday, month, century, year);
}
45  Using Arduino / Programming Questions / Re: VirtualWire receiver never gets its message on: May 19, 2013, 02:31:05 am
Quote
Im not sure what you mean, I did attach the whole program as an additional file and the code within the post is just the example code that I used to prove that everything is wired up and functioning correctly.
didn't see that part. it was late. sorry.
Pages: 1 2 [3] 4 5 ... 8