Show Posts
|
|
Pages: [1] 2 3 ... 5
|
|
1
|
Using Arduino / Programming Questions / Re: multi-menu 1 encoder
|
on: Today at 08:08:34 am
|
|
I navigate the menu and when I get to for example "change min" I select. I expect to be taken to the void changeMin but nothing happens. The time is displayed but if I use the encoder to change min. I just end up in a different menu.
|
|
|
|
|
2
|
Using Arduino / Programming Questions / Re: Some issue with Adruino Mini Pro and a SIM900 module
|
on: May 19, 2013, 04:22:45 pm
|
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.
|
|
|
|
|
5
|
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. #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); }
|
|
|
|
|
8
|
Using Arduino / Programming Questions / Lcd Clock almost finished.
|
on: May 18, 2013, 05:09:52 pm
|
my project is almost there. Here is the complete code. Just need some help with the following. I can navigate the menu but when I break out of the menu to change any of the RTC parameters the encoder just navigates the menu again. I can only change parameters of the RTC using the encoder push button. What I want is to change the parameters using the encoder. #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); }
|
|
|
|
|
9
|
Using Arduino / Programming Questions / Re: For loop
|
on: May 18, 2013, 04:39:09 pm
|
|
Thanks for taking the time to give an example. Mine was very contrived but I'm trying to get a better understanding of the for loop. Your example has helped me understand how it all comes together.. Thanks all of you for the help.
|
|
|
|
|
12
|
Using Arduino / Programming Questions / For loop
|
on: May 18, 2013, 03:22:29 pm
|
|
I have read about the "For loop" statement but could someone explain why you would use such a statement. I have read the explanations on the web and in books and as I understand it counts through a loop.
Why would you use it. I have seen examples but dont understand "when" it would be used.
|
|
|
|
|
13
|
Using Arduino / Programming Questions / Switch case
|
on: May 09, 2013, 07:07:36 pm
|
I'm using a rotary encoder to navigate a menu and use "switch" statements to control the 3 functions of the encoder. 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 rotation menu.moveRight(); break; case 2: //Encoder left rotation menu.moveLeft(); break; } lastButtonPushed=0; //reset the lastButtonPushed variable }
To get this far I have the rotary encoder set up as below void readEncoder() //read the encoder and set lastButtonPushed to values used by navigateMenu() { n = digitalRead(encoder0PinA); if ((encoder0PinALast == HIGH) && (n == LOW)) { if (digitalRead(encoder0PinB) == LOW) { lastButtonPushed = 1; } else { lastButtonPushed = 2; } } encoder0PinALast = n; }
What I would like to know is can I also use the same rotary action to increase a parameter instead of moving Right (case 1) or Left (case 2) through a menu. If it is possible, how would it be done? I have a lot of views but no one has responed. can anyone offer any help on this matter
|
|
|
|
|
14
|
Using Arduino / Programming Questions / Lcd clock and Rotary encoder.
|
on: May 06, 2013, 12:11:29 pm
|
|
I am making a clock using a Pcf 8563p as the (RTC) chip. The clock displays on an LCD and I can change the time and date using a Rotary encoder. But TWO things are bothering me and would like some advice on how to solve the following.
1, The date displays as mm/dd/yyyy and I would like dd/mm/yyyy
2, I use a rotary encoder to move through the menu. But, when I want to change either the Time or Date I have to keep pressing the encoder button to increment the digits. Also when I come out of the variable I have set. The digits I had just set increment by an additional 1. so for example if I set the hours to 10 by pressing down on the encoder button then Rotate the encoder to the Minutes the Hour becomes 11.
How do I stop this additional digit increment, and what do I change in my code to increment the digits using "Rotary action" of the encoder instead of the "Push button action" of the encoder.
Heres the code attached below
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: changing clock/date setting on Real Time Clock pcf8563
|
on: January 21, 2013, 02:37:06 pm
|
Thanks to all. I have it working now. This last bit solved the issue. On each pass through loop(), you are testing whether the switch connected to minButton is pressed. If it is, you set the time to 5:30:14, then increment the min variable and return.
You need to move the local variables hour, min, and sec from the function to global space.
Then, you need to call setTime AFTER incrementing min.
Karma awarded.
|
|
|
|
|