Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 244
811  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 27, 2014, 12:31:22 am
Ok, the same coordinates you use to draw/fill in the button/circle are the same ones you use to touch the circle. This way it is just simple copy and paste. The tx and ty are the actual touch data from,
Quote
myTouch.read();
  int tx = myTouch.getX();
  int ty = myTouch.getY();
  int XC= tx > 320? 0 : tx;
  int YC= ty > 240? 0 : ty;
Except in this case, your passing the fixed touch data XC and YC into the getButton function. You can actually do without the part above, and just have like this, boolean button2 = myTFT.LatchButton(220,135,310,225,1); Notice no tx or ty, thats because I actually implemented it into the library itself.

The only real reason you would use the function with tx and ty, is if you want to use the raw touch data from myTouch.TP_X and myTouch.TP_Y. This is actually faster but it requires you to map the screen and use the map function. Like this,
Quote
myTouch.read();
  tx = myTouch.TP_X;
  ty = myTouch.TP_Y;
  XC = constrain(map(tx, 205, 3900,0,239),0,239); // raw touch data converted to pixel data
  YC = constrain(map(ty, 300, 3850,0,319),0,319);//------------------------------------------

Oh and btw, the 1 in "LatchButton(220,135,310,225,1)" is a identification number, which as of right now, you can have 10 in total. You can have as many as you need, but you will need to change the value of this line in the .h file #define Num_Of_Buttons 10

My library doesn't draw or fill in the button when you add in the button functions, so you need to make those seperate, which is also why the sketch has a makeButton function.
Quote
void makeButton()
{
  myGLCD.setColor(255,255,255);
  myGLCD.drawCircle(55,180,50);// circle button 1

  myGLCD.setColor(255,0,0);
  myGLCD.fillCircle(265,55,50);// circle button 2

  myGLCD.setColor(0,255,0);
  myGLCD.drawRect(10,10,100,100);// rect button 1

  myGLCD.setColor(0,0,255);
  myGLCD.fillRect(220,135,310,225);// rect button 2
}

It is called in the setup function so it only runs once, but you can lock and unlock it if you ever need to remake the buttons.
812  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 11:38:34 pm
Your welcome, I'm happy to hear my library was able to help you.

813  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 11:23:22 pm
So instead of a latching button, change it to touch button, myTFT.TouchButton(220,135,310,225);
814  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 11:14:24 pm
You need to add those at the top, they are boolean, here:

boolean last = LOW, latch = false;
815  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 11:09:57 pm
You would do it like so, put this after this line boolean button2 = myTFT.LatchButton(220,135,310,225,1);
Code:
  if (button2 != last)
  {
    latch = !latch;
    if(latch)
    {
      myGLCD.setColor(255,0,0);
      myGLCD.fillRect(220,135,310,225);// rect button 1
    }
    else
    {
      myGLCD.setColor(0,255,0);
      myGLCD.fillRect(220,135,310,225);// rect button 1
    }
  }
  last = button2;

The number in the center will still show as blue but you can disable the text by commenting it out.
I am still adding things to this library, so I will add this in it. You can follow the progress with this link.
New TFT_Extension
816  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 10:56:18 pm
? there boolean so it should be 0 and 1.

Being that my LCD and sketch uses the older library, there might be things that you need to set like text transparency.

Compare the sketch that came with the UTFT library to what I have, in my sketch. You should see text.
817  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 10:39:01 pm
This is incorrect,
Quote
UTFT myGLCD(38,39,40,41,ITDB32S);
It should be UTFT myGLCD(ITDB32S,38,39,40,41);

UTFT::UTFT(byte model, int RS, int WR,int CS, int RST, int SER)
818  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 10:28:58 pm
Nothing at all? Not even these?
Quote
myGLCD.setColor(255, 0, 0);//red box fill
  myGLCD.fillRect(0, 0, 319, 13);//text box
819  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 10:03:54 pm
Yea, try it. Look at one of the example sketches to see how to set it up.
820  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: March 26, 2014, 08:25:51 pm
Yea, of course, but you will need a latch.

Read the coords, if the button is pressed, and not held, change the button color and state.

Here is an example you can use, but instead of an actual button, you can use the touch screen coords.
Code:
byte LEDpin = 13; //on-board LED
byte ButtonPin = 2; //digital pin 2

boolean button,last = LOW;
boolean latch = false;

void setup() {
  pinMode(LEDpin, OUTPUT);
  pinMode(ButtonPin, INPUT);
}

void loop()
{
  button = digitalRead(ButtonPin);
  if (button == HIGH && button != last)
  {
    latch = !latch;
    latch ? digitalWrite(LEDpin, HIGH): digitalWrite(LEDpin, LOW);
  }
  last = button;
}

Or if you want, you can download my TFT library, where I have already done just that.
TFT_Extension.zip

You may need to change the libraries in my example sketches. I have the old ITDB02 libraries, but my TFT library should work with the ones you have. If not, then let me know and I'll tell you what to fix to get it to work.
821  Using Arduino / Project Guidance / Re: Wristwatch with four buttons and Nokia 5110 on: March 26, 2014, 05:56:39 pm
@raschemmel

Those might be a little too big to fit into a watch, he might want these instead.
Mini tactile buttons.
822  Using Arduino / Project Guidance / Re: Hi new to this wonderful new World of Arduino. on: March 26, 2014, 05:52:47 pm
Do any of the servo need to move at the same time, because you can probably multiplex them to save pins.
Also yes it can be done wirelessly with two Arduinos. You can use RF, bluetooth, Xbees, and/or IR, but either way you will need another Arduino as a controller.

You will need a power supply capable of supplying enough current to all the servos and the possibly the Arduino too.

823  Using Arduino / Project Guidance / Re: Wristwatch with four buttons and Nokia 5110 on: March 26, 2014, 05:29:07 pm
You might be in a little too far over your head with this project. Its easy to do with breadboards and wires, but for something to look like a wristwatch and still function, that's a little much.
 
All  those parts might stick out a little too far, so if you want to keep things compact, you might want to get bare components.

Find out where you can get the ATmega168 chip without a board so you can make your own PCB, then see if you can find a low power LCD. I'm not sure if that Nokia LCD will work with 3.3V or if it needs 5V. These are things you need to research and plan out. For buttons, you can try to get some mini tactile buttons online, costs may vary so shop around.

As always, start with regular components first and get it to work.

EDIT, I took to long -_-
824  Using Arduino / Programming Questions / Re: Slight discrepancy in my code, where am i going wrong? on: March 26, 2014, 05:05:49 pm
Ok, well what you could do is if the button is pressed and held, then you can have a counter increase from 0 to 99. OR you can have the code check to see if the button is pressed for a certain amount of time, say 2 seconds. Then if the button is held down for 2 seconds then you can run the stepper 100 steps and set a flag. Once the stepper is done, the flag is set and the button is released, you can step in the other direction until that is done.

Here is a sketch to get you started.
Code:
const byte buttonPin = 2;     
const byte ledPin =  13;

boolean buttonState = 0;
boolean  lastReading = 0;
boolean Released = false;
long onTime = 0;

void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin, INPUT);     
}

void loop(){
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH && lastReading == LOW) // first check to see if the button is pressed ie. HIGH and it is different from lastReading
  {
    onTime = millis(); // record time
    lastReading = HIGH; // prevents the code from entering this IF statement, until lastReading is set to LOW again.
  }

  if (buttonState == HIGH && lastReading == HIGH) // button is still held down
  {
    if ((millis() - onTime) > 3000) // check to see if button is held down for 3 seconds
    {
       Released = false; // button is still being held down.
      // Clockwise 100 steps here
      digitalWrite(ledPin, HIGH); // if button is held down for 3 seconds, LED on
    }
    else
    {
      digitalWrite(ledPin, LOW); // otherwise LED remains off
    }
  }

  if(buttonState == LOW && Released == false) //check to see if the button is LOW and was released, then start over.
  {
       // counterclockwise 100 steps
       lastReading = LOW;
       Released = true;
   }
}

You will need to add another boolean variable here to lock out this part after the stepper does its 100 steps, otherwise it will keep stepping.
825  Using Arduino / Programming Questions / Re: Slight discrepancy in my code, where am i going wrong? on: March 26, 2014, 04:22:36 pm
Quote
despite the code quite clearly specifying to only to move 100 steps
Actually your code is constantly being told to do 100 steps, regardless if the button is pressed or not.

What exactly do you want it to do?
Pages: 1 ... 53 54 [55] 56 57 ... 244