Show Posts
Pages: 1 ... 41 42 [43] 44 45 ... 85
631  Using Arduino / Displays / Re: utft code issues on: March 21, 2013, 05:09:46 pm
It would be helpful if you could include the actual error message?

Code:
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
     
      if (50>=MainScreen && 100<= MainScreen && 100>= MainScreen && 170<MainScreen)
      {
         ScreenTo(0, 0, 300, 300);            //
      }

What is the variable MainScreen and where is it declared? I would have thought you should be comparing 50, 100, 170, etc to the variables x and y, which contain the coordinates you read form the touchscreen.

I would suggest that you should start on simpler examples of how to use variables and structure code. The examples that come with the Arduino IDE are a good place to read and understand how some of these basic concepts work. Once you have done that, maybe attempt this project, which is more complex.
632  Using Arduino / Displays / Re: Arduino LCD via I2C on: March 20, 2013, 10:32:07 pm
A backward compatible LCD library can be found at

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

Handles all sorts of serial LCDs.
633  Using Arduino / Programming Questions / Re: Sensor Values on: March 20, 2013, 07:44:26 pm
Have you tried to use map()

Code:
percentage = map(variable, 800, 850, 0, 100);
of course, this assumes a linear relationship (ie, each value read from the analog port is 2% of full scale).

If you want to keep it a multiple of 10% then you could use

Code:
percentage = (percentage/10) * 10;
or
precentage -= (percentage % 10);
to eliminate the last digit.
634  Using Arduino / Displays / Re: Custom character with Sparkfun Serial LCD on: March 20, 2013, 07:36:50 pm
You should be able to use the new 'fm' LiquidCrystal libraries with a serial device. You can get them at

https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home

and they are a direct replacement for the libraries that are supplied wit hthe IDE download.
635  Using Arduino / Displays / Re: Custom character with Sparkfun Serial LCD on: March 20, 2013, 03:57:21 pm
What is your code?

Are you useing lcd.write() or lcd.println()? the second will not work because:
1. It will always put a newline after the characeter (which I bet is two vertical bars)
2. It has trouble oprinting the character 0 as it usually means the end of the string (ie, you are printing and empty string).

In any case, hard to make any relevant comment unless you post code.
636  Using Arduino / Displays / Re: utft code issues on: March 20, 2013, 03:54:15 pm
Code:
  if (myTouch.dataAvailable())
  {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
     
      ScreenTo(0, 0, 300, 300);            //
                                                       //   dont no what to do here??????
      MainScreen(50, 100, 100, 170);   //
   }

All that this code does is read the x and y coordinates and then do screen 1 followed by screen 2. YOu need to put some logic in place to determine which 'button' has been pressed and then call the right screen - once you have x and y you need to check ofthe touch is in the 'button' area for each menu item. I don't know what size your buttons are, so you will need to change the code below:

Code:
{
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
     
      if (x>=BUTTON1_XMIN && x<= BUTTON1_XMAX && y>= BUTTON1_YMIN && y<=BUTTON1_YMAX)
      {
         ScreenTo(0, 0, 300, 300);            //
      }

      if (x>=BUTTON2_XMIN && x<= BUTTON2_XMAX && y>= BUTTON2_YMIN && y<=BUTTON2_YMAX)
      {
        MainScreen(50, 100, 100, 170);   //
      }
   }

Generally, howebver, you code needs to be reorganised or you will come into trouble. For example, you do not draw the button on the screen, so how does the user know where to press? Once you exit from ScreenTo or Menu, what happens next (maybe this will be completed later?).
637  Using Arduino / LEDs and Multiplexing / Re: 1602 LCD with Keypad / Need data sheet or book on: March 19, 2013, 06:50:14 am
For the LCD look at the LiquidCrystal library on the arduino main site.

If you want example code to hack, look at the libraries at the location in my signature block. I have a small library that handles the buttons on an LCD and also a sketch to implement a countdown timer. Not exactly the same as your requiremens but probably a good starting point.
638  Using Arduino / Programming Questions / Re: How to write to textfile to the same line not next one ? on: March 17, 2013, 10:32:01 pm
Quote
Serial monitor writes it in one line, when the code is this:

That cannot be true as there is no println() in your code.

Quote
it becomes each number in next line...

That is definitely true as you have a println() for every line.

639  Using Arduino / Programming Questions / Re: How to declare arrays in another (not main) tab? on: March 17, 2013, 10:28:32 pm
Quote
you cannot state an array as extern without stating the array size

You can declare it as a point to the same type as the array and it would have to work ...
640  Using Arduino / LEDs and Multiplexing / Re: Using one Slave Select pin for two devices on: March 17, 2013, 09:44:50 pm
I don't see why that approach would not work. The other signals are active all the time and it is up to the board to use/ignore the signales based on the SS enable.

Will there be any issues during initialisation?
641  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 05:41:49 pm
A couple of other suggestions:
* Your code has a lot of repetition in it. This means that you should be able to define a functin to do one drum (passing in the right parameters) and then call it with different parameters to do the other drums. This will make maintaining the code easier (eg, to change the way all drums work you only need to change the one function).
* Consider using arrays to store repetitive data and implify processing your code (see below for an example)
From
Code:
// define the pins we use
#define switchAPin 10
#define switchBPin 9
#define switchCPin 8
#define switchDPin 7
#define switchEPin 6
#define switchFPin 5
#define switchGPin 4
#define switchHPin 3
int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int switchDState = LOW;
int switchEState = LOW;
int switchFState = LOW;
int switchGState = LOW;
int switchHState = LOW;
to
Code:
#define NUMNOTES 8
const uint8_t switchPin[NUMNOTES] = { 10, 9, 8, 7, 6, 5, 4, 3 };
int switchState[NUMNOTES] = { LOW, LOW, LOW, LOW, LOW, LOW, LOW, LOW };

Get the idea? You can do the same with the drum notes. The you can go through the whole lot using a 'for' loop in a few statements, as long as the array indices (ie, the 0, 1, etc) for the arrays are congruent for all arrays.

Code:
for (uint8_t i=0; i<NUM_NOTES; i++)
{
  currentSwitchState = digitalRead(switchPin[i]);
  if( currentSwitchState == LOW && switchState[i] == HIGH ) // push
    noteOn(drumchan, note_drum[i], 100);
  else if( currentSwitchState == HIGH && switchState[i] == LOW ) // release
    noteOff(drumchan, note_drum[i], 0);
  switchState[i] = currentSwitchState;
}
642  Using Arduino / Programming Questions / Re: Initialising static class variables with external data - is there a better way? on: March 17, 2013, 04:47:26 pm
Quote
a particular element could have a reference to the screen that it belongs to.

This is how it started. For each element I passed in the pointers to the 2 UTFT objects. I must say it got a bit cumbersome and I was repeating these pointers all over the place, taking up precious bytes.

I guess that if something like MD_GUI.create(<graphic element>) was possible, then the it would mean that different objects could be initialised to belong to alternatiove screens. In that situation, how would a reference to the individual objects be handled without creating lots methods? If an object is created as per above, does it automatically just belong in the namspace of the base GUI object?
643  Using Arduino / Programming Questions / Re: Creating a timer that can reset when a sensor activates on: March 17, 2013, 03:51:01 pm
A look at the MD_AButton library linked from my footer below may be helpful. It does a similar thing to what you want to do in a different situation, but the technique is the same.
644  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
Quote
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.
645  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.
Pages: 1 ... 41 42 [43] 44 45 ... 85