Show Posts
Pages: 1 ... 41 42 [43] 44 45 ... 85
631  Using Arduino / Programming Questions / Re: Initialising static class variables with external data - is there a better way? on: March 17, 2013, 03:41:19 pm
The implication here, still, is that you will have multiple instances of the MD_GUI class that share the same display and touch screen.

That is exactly the case. The MD_GUI base class is only instantiated as a by product of creating other graphics elements (buttons, checkboxes, etc). All share the same physical user interface (screen/touch screen) that is managed through the UTFT library.

Is there a better way to do what I need to do? Clearly if I can generalise so that if I ever needed to have a multiple displays (eg serial displays), everything still works without refactoring the code, it it worth doing that now.
632  Using Arduino / Displays / Re: [Solved] LCD crashes on characters with first/last 4 bits = 1111 on: March 17, 2013, 08:16:58 am
This usually mean that the contrasts for the LCD is not set correctly. There is usually a pot that is used to set this.
633  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 08:14:54 am
The main difference is the piezo returns an analog value instead of a digital, so you will need to deal with values that are 0-1023 rather than HIGH/LOW.

One approch may be to use a threshold value (x) that over which you treat it as HIGH and below which it is LOW. That means you can reduce the number of changes to your current code.

Alternatively, you can use the additional information from a piezo to include 'loudness' of the drum. In this case you could use the value 0-1023 as an indication of how hard the drum is hit and, therefore, how loud it would be.

I would suggest you experiment with one piezo and the serial monitor, printing the values, to get a feel for what hitting the piezo does.
634  Using Arduino / Programming Questions / Re: how to convert g-code to electrical signal??? on: March 17, 2013, 04:05:28 am
Someone has already written a g code interpreter for the arduino. I came across it when I was googling CNC and arduino a while back.

Edit: google arduino g code and there are a few examples. Grbl is the one I saw previously.
635  Using Arduino / Programming Questions / Re: Do I have a memory problem on: March 17, 2013, 04:03:30 am
Long is 4 bytes. If you have 120 of them then the array is just under 25% of your available RAM. Whether you have a memory problem depends on what else you are doing...
636  Using Arduino / Sensors / Re: Trouble with Ping))) Sensor PLEASE HELP! on: March 17, 2013, 03:57:23 am
If you are powering the servo from the arduino then you should try using direct power. Servos draw too much power from the arduino pins.
637  Using Arduino / Programming Questions / Re: Initialisaing static class variables with external data - is there a better way? on: March 17, 2013, 12:42:30 am

Using an instance implies that there is something about this instance that is important
That's probably why I was thinking this was not the right way.

Anyway, now changed to
static void begin(UTFT *S, UTouch *T) { _S=S; _T=T; };

and calling this from setup()
void setup()
  MD_GUI::begin(&myGLCD, &myTouch);

Much happier, thanks Nick.
638  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 12:14:19 am
... and these
639  Using Arduino / Programming Questions / Initialising static class variables with external data - is there a better way? on: March 17, 2013, 12:06:18 am
I have static class variables in my own class that contain pointers to UTFT objects, used for graphics and touchscreen control. These are used by methods in my own classes and it makes sense to have them there once only available for use by all methods rather than an instance per object.

After a bit of research, I have the static variables working ok. However, most of the examples I can find use statics to keep track of internal class parameters (eg, the number of objects created, the highest number for something, etc) which means thay can be
statically initialised at compile time. My value is not known until run time and needs to be externally initialised.

All my classes are derived from a base class that contains common parameters and functions. As such there is no need to use the base class that owns the static data,  but i have 'kludged" an initialisation that allows me to pass in the UTFT object pointers at run time (see the definition below, in the constructor)

class MD_GUI
// Attributes
int8_t id; // return value when the button is pressed
bool enable; // is enabled (true by default)
uint16_t value; // current value

void begin(UTFT *S, UTouch *T) { _S=S; _T=T; };

static UTFT *_S; // the display
static UTouch *_T; // the touch screen

In the setup() function I then declare a short lived local instance of the object, just to initialise the statics:
void setup()

GUI.begin(&myGLCD, &myTouch);

This works, because the static variables persist after the object instance is killed off, but it does not seem an 'elegant' solution to the problem.

Is there another way to do this that is more in line with a standard practice I can learn?
640  Using Arduino / Displays / Re: Custom character doesn't display on Liquid Crystal LCD. on: March 16, 2013, 07:59:51 pm
I would move it out of the loop and put it in setup. Even with your delay I think the screens don't like to be hammered with data (probably in the libraries). You also don't need to set the character to zero at all - just define what you need.
641  Using Arduino / Programming Questions / Re: I don't understand the UTouch library. on: March 16, 2013, 02:01:53 am
Are you touching in the right area?
Is the text color visible against the background?

You have not shown all your code, so we have no clue as to what is happening. In many cases the cause of an issue is nowhere near where you see the symptoms. I would suggest you post all your code.
642  Using Arduino / Programming Questions / Re: I don't understand the UTouch library. on: March 15, 2013, 01:53:18 am
What does not work? What are you expecting to happen that does not?
643  Using Arduino / LEDs and Multiplexing / Re: controlling several LED's with one button on: March 15, 2013, 01:47:20 am
What have you got so far?
What is your circuit?
644  Using Arduino / Programming Questions / Re: How to declare arrays in another (not main) tab? on: March 14, 2013, 11:10:38 pm
Have you declared the macro arracys as extern? If you haven't, try it. If it still does not work, post the two files...
645  Using Arduino / Programming Questions / Re: extract 4 bits from 8 bits .... on: March 14, 2013, 08:38:42 pm
The reverse.

You shift to the right by how many bits you need (creating zeros in the bottom part) and then 'or' in the other part

(x << 3) | y
Pages: 1 ... 41 42 [43] 44 45 ... 85