Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Run function only for a period of time on: February 03, 2013, 11:24:11 am
Hi,

Thanks a lot for that. Yes, I mean from a button press. The overall theme is to start the system (power on), do some adjustments in the preference menu and then from the menu start the system for a defined period of time. So I will need a startTime variable.

I will try to separate the two - thanks for the hint.

Cheers!
2  Using Arduino / Programming Questions / Run function only for a period of time on: February 03, 2013, 10:48:40 am
Hi,

I would like to run a function only for a specified period of time.

Code:
int totalTime = 1; // in minutes
int Interval = 2; // in seconds
int counter = 0;

unsigned long currentTime = 0;
unsigned long previousTime = 0;

void setup () {

Serial.begin(9600);
Serial.println("Start");
}

void loop() {
 
myCount();

}

void myCount(){

  currentTime = millis();
 
  if (currentTime - previousTime > (Interval*1000)){

previousTime = currentTime;
counter = counter+1;
Serial.println(counter);
  }
}

In my code totalTime sets the overall period of time for which the function should run. My first attempt was to have a variable startTime and check this against the currentTime - totalTime. My problem is that when I put the code like below startTime gets overwritten each time.

Code:
void myCount(){

  currentTime = millis();
  startTime = millis();
 
  if (currentTime - previousTime > (Interval*1000) && startTime + totalTime < currentTime){

previousTime = currentTime;
counter = counter+1;
Serial.println(counter);
  }
}

How would you implement this? Many thanks in advanve!
3  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: February 01, 2013, 11:49:27 am
If I debug my code with Serialprints it is giving me the correct button.

If I put my code like this:

Code:
int read_LCD_buttons() {

adc_key_in = analogRead(0);

        if (adc_key_in < 50)   return btnRIGHT; 
if (adc_key_in < 200)  return btnUP;
if (adc_key_in < 400)  return btnDOWN;
if (adc_key_in < 600)  return btnLEFT;
if (adc_key_in < 800)  return btnSELECT;

return btnNONE;
}

int navMenu() {

buttonPressed = read_LCD_buttons();

if(buttonPressed != lastButtonPressed) {

    switch (buttonPressed) {
    case btnUP:
      return MW_BTU;
      break;
case btnDOWN:
      return MW_BTD;
      break;
    case btnSELECT:
      return MW_BTC;
      break;
    case btnLEFT:
      return MW_BTL;
      break;
   case btnRIGHT:
return MW_BTR;
break;
case btnNONE:
      return MW_BTNULL;
      break;
    }
}

lastButtonPressed = buttonPressed; 
}

I would have thought, that
Code:
if(buttonPressed != lastButtonPressed) {
ensures that a button can't be pressed more than once, can it?
4  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: February 01, 2013, 09:43:57 am
Hi there,

Got another problem which is that the input seems to be too fast so that I flip through the menu without the possibility to navigate one by one.

This is my code:

Code:
#include <Wire.h>
#include <LiquidCrystal.h>
#include <MENWIZ.h>
#include <EEPROM.h>

const int btnNONE = 0;
const int btnUP    = 1;
const int btnDOWN  = 2;
const int btnLEFT  = 3;
const int btnRIGHT = 4;
const int btnSELECT = 5;

menwiz menu;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

int adc_key_in = 0;

int buttonPressed = 0;
int lastButtonPressed = 0;

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 100;    // the debounce time; increase if the output flickers

int list,sp = 0;

extern byte MW_navbtn;


void setup() {

_menu *r,*s1,*s2;

menu.begin(&lcd,16,2);
menu.addUsrNav(navMenu,4);
MW_navbtn=4;

r=menu.addMenu(MW_ROOT,NULL,F("Root"));
s1=menu.addMenu(MW_SUBMENU,r, F("Node1"));
s2=menu.addMenu(MW_VAR,s1, F("Node3"));
s2->addVar(MW_LIST,&list);
s2->addItem(MW_LIST, F("Option1"));
s2->addItem(MW_LIST, F("Option2"));
s2->addItem(MW_LIST, F("Option3"));
s2=menu.addMenu(MW_VAR,s1, F("Node4"));
s2->addVar(MW_AUTO_INT,&sp,0,120,10);

menu.addSplash("LiPanCo\n2012 v01\n", 2000);
menu.addUsrScreen(&myMenuCall, 5000);
}

void loop() {

  menu.draw();
}

void myMenuCall() {
 sprintf(menu.sbuf,"Uptime (s): %ld\nFree mem  : %d\n\n",millis()/1000,(int)menu.freeRam());
  menu.drawUsrScreen(menu.sbuf);
 
}


int read_LCD_buttons() {

adc_key_in = analogRead(0);

if (adc_key_in < 50)   return btnRIGHT; 
if (adc_key_in < 200)  return btnUP;
if (adc_key_in < 400)  return btnDOWN;
if (adc_key_in < 600)  return btnLEFT;
if (adc_key_in < 800)  return btnSELECT;   
if (adc_key_in > 1000) return btnNONE;

return btnNONE;
}

int navMenu() {
buttonPressed = read_LCD_buttons();

if (buttonPressed != lastButtonPressed) {

lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {

    switch (buttonPressed) {
    case btnUP:
      return MW_BTU;
      break;
case btnDOWN:
      return MW_BTD;
      break;
    case btnSELECT:
      return MW_BTC;
      break;
    case btnLEFT:
      return MW_BTL;
      break;
    case btnRIGHT:
return MW_BTR;
break;
case btnNONE:
      return MW_BTNULL;
      break;
    }
}

lastButtonPressed = buttonPressed; 
}

I would have expected that
Code:
if (buttonPressed != lastButtonPressed) {

lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {

...

prevents this as it does in other sketches but it doesn't seem to work here. Any ideas?

Many thanks for any help in advance. Cheers!
5  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 04:59:50 pm
I have deinstalled everything and reinstalled afterwards. I don't know what it made not working but now it works - oh dear smiley

Many thanks for your help and patience.

Cheers!
6  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 02:53:17 pm
In this thread at post 316 there is my code that is working on your hardware ....
Quote
Re: MENWIZ: yet another character lcd menu wizard library
« Reply #316 on: January 09, 2013, 09:59:40 PM »
(is on page 22)
you can try it then start to modify it for your convenience you will have the buttons working too ...

Thanks for the offer. I have copied the code over but still get the same error message smiley-sad

Code:
In file included from Splash.cpp:7:
/Users/MyName/Documents/Arduino/libraries/MENWIZ/MENWIZ.h:214: error: ISO C++ forbids declaration of 'LCD' with no type
/Users/MyName/Documents/Arduino/libraries/MENWIZ/MENWIZ.h:214: error: expected ';' before '*' token
7  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 01:06:18 pm
Unfortunately I can't get it to work properly. Here is my code:

Code:
#include <Wire.h>
#include <LiquidCrystal.h>
#include <MENWIZ.h>
#include <EEPROM.h>


LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

menwiz tree;

int  list, sp=110;


void myfunc(){
   Serial.println("ACTION FIRED");
  }


void setup(){

//_menu *r,*s1,*s2;

tree.begin(&lcd, 16, 2);

tree.addSplash("Library running", 2000);
}


void loop(){

  tree.draw();
}

But I get the following error message:

Code:
In file included from Splash.ino:3:
/Users/MyName/Documents/Arduino/libraries/MENWIZ/MENWIZ.h:214: error: ISO C++ forbids declaration of 'LCD' with no type
/Users/MyName/Documents/Arduino/libraries/MENWIZ/MENWIZ.h:214: error: expected ';' before '*' token

Would it be possible to fix that if I would you the new LiquidCrystal library? If yes, I would need to ask the same question as before as to how my statement for initialization would need to look like smiley

Many thanks for your help!
8  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 30, 2013, 01:31:09 am
Hi,

Sorry if that was unclear.

At the moment I am using the standard LiquidCrystal library with the following statement:

Code:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

In the MENWIZ quicktour example the standard LiquidCrystal library is replaced with the New LiquidCrystal library from https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

The statement for initialization in the example looks as follows:

Code:
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3,POSITIVE);

My question now is, how should the statement look like for my LCD?
9  Using Arduino / Programming Questions / Re: LyquidCristal / 10-1 = 90? on: January 29, 2013, 05:13:50 pm
Quote

Hi Paul,

thanks a lot for the tip. This is what my code now looks like and works like a charm. Many thanks!

Code:
void loop() {
lcd.setCursor(0,1);

lcd.print(value);
lcd.print(" "); // Overwriting Zero

buttonState = read_LCD_buttons();

// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
         // if the state has changed, perform action
         if (buttonState == btnUP) {
value = value+1;
         }
         if (buttonState == btnDOWN) {
value = value-1;
         }
}

lastButtonState = buttonState; 
}
10  Using Arduino / Displays / Re: MENWIZ: yet another character lcd menu wizard library on: January 29, 2013, 04:26:05 pm
Hi all,

Looking for a nice and simple library I have found MENWIZ and hence would like to test it for my project. Unfortunately I face some issues setting up my LCD. Currently I still use the included LyquidCrystal library with my DFRobot LCD Shield.

This is what I use for initialization:

Code:
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

with
  • 8 for RS
  • 9 for E
  • 4 for D4
  • 5 for D5
  • 6 for D6
  • 7 for D7

What would be the equivalent for the New LiquidCrystal library?

Code:
LiquidCrystal_I2C lcd(???);

Do I need to remove the LyquidCrystal library from my libraries folder or can they coexist?

Many thanks in advance!
11  Using Arduino / Programming Questions / Re: Stepper Absolute Position ... how to on: January 28, 2013, 04:58:34 pm
Have you had a look into the AccelStepper library? If I remember correctly they support absolute movement for stepper motors.

http://www.open.com.au/mikem/arduino/AccelStepper/index.html
12  Using Arduino / Programming Questions / Re: LyquidCristal / 10-1 = 90? on: January 28, 2013, 03:30:53 pm
Hehe, thanks for that  smiley

I have put the delay in there so that I don't get a very high number although I just pressed once. Assuming from your comment that there are better ways to realize this?

Thanks!
13  Using Arduino / Programming Questions / Re: LyquidCristal / 10-1 = 90? on: January 28, 2013, 03:11:13 pm
Hi both,

Thanks a lot.

I was going to write a lot of if statements - so thanks for the help  smiley-red

Would it be better style to call a function doing the calculation or is the Switch statement fine?

Cheers!
14  Using Arduino / Programming Questions / LyquidCristal / 10-1 = 90? on: January 28, 2013, 02:48:55 pm
Hi there,

I am running this little code to add / substract each time I press a button:

Code:
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);

lcd.print("Press a Button");
}
 
void loop() {

lcd.setCursor(0,1); // column 1, row 2

lcd.print(value);

lcd_key = read_LCD_buttons();
 
  switch (lcd_key) {
case btnUP:
value = value+1;
delay(300);
break;
case btnDOWN:
value = value-1;
delay(300);
break;
}
}

After I have pressed 10 times the value is calculated correctly being 10. If I then substract by pressing once it displays 90 instead of 9. Where is the error or what do I need to add / change?

Many thanks
aufruf
15  Development / Other Software Development / TextMate for Arduino on: January 25, 2013, 04:35:12 am
Hi all,

As I would like to use TextMate as my editor I am currently trying to get it working together with Arduino. I have downloaded a TextMate Bundle for Arduino from here: https://github.com/nasser/arduino.tmbundle

Unfortunately I get the following error message:

Code:
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -DF_CPU=16000000L -DARDUINO=100 -I/Users/larslamar/Documents/Arduino/Blink -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/libraries/EEPROM/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Esplora/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Firmata/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/LiquidCrystal/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SD/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SD/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SPI/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Servo/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SoftwareSerial/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Stepper/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Ethernet/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/SD/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/WiFi/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/ -I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include/avr -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard -mmcu=atmega328p /Applications/Arduino.app/Contents/Resources/Java/libraries/Esplora/Esplora.cpp -o /Applications/Arduino.app/Contents/Resources/Java/libraries/Esplora/Esplora.o
/Applications/Arduino.app/Contents/Resources/Java/libraries/Esplora/Esplora.cpp:54: error: 'A11' was not declared in this scope
make: *** [/Applications/Arduino.app/Contents/Resources/Java/libraries/Esplora/Esplora.o] Error 1

Any suggestions what is going wrong here?

Many thanks!
aufruf
Pages: [1]