Show Posts
Pages: 1 ... 42 43 [44] 45 46 ... 253
646  Using Arduino / Programming Questions / Re: Debounce and more! on: June 11, 2014, 04:10:19 pm
What you have is wrong, but please post your full code anyways.

What you need to do is:
1) debounce the button
2) record the state and time "millis()" of that button after it is debounced
3) continuously check the state of the button and see if the currentTime - oldTime >= 2000
4) if the button is HIGH or Pressed and time difference is equal to or greater than 2 seconds, do your function, else keep checking the difference.

Here is a working example you can try.
const byte buttonPin = 2;     
const byte ledPin =  13;

boolean buttonState = 0;
boolean  lastReading = 0;
unsigned 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
      digitalWrite(ledPin, HIGH); // if button is held down for 3 seconds, LED on
      lastReading = LOW;
      digitalWrite(ledPin, LOW); // otherwise LED remains off
647  Using Arduino / Programming Questions / Re: 2 Shift register with 16 LEDs on: June 11, 2014, 01:50:23 pm
Instead of sending out your pattern(1001010010...), send out all zeros.
648  Using Arduino / Displays / Re: Adafruit library TFT colours on: June 11, 2014, 11:34:53 am
You can look in the .h or .cpp files, they are usually outline at the top of the files.
649  Using Arduino / Programming Questions / Re: Debounce and more! on: June 11, 2014, 10:19:12 am
Post your code. Please use code tags, they are the # symbol above the smiley face. [ code ] ... [/ code]

i  make faults all the time!
What faults? Can you post the errors your getting.
650  Using Arduino / Programming Questions / Re: Debounce and more! on: June 11, 2014, 09:43:10 am
Do you understand the debounce sketch? It reads the state of a button and stores that state in a temporary variable, then it lets some time pass (50 milliseconds or so) and reads the state again. If the previous state matches the new state, then it does something to indicate that the two states match.

However what you want to do, is extend that time to 2000 milliseconds or 2 seconds and check if the two states are the same. I would recommend you check to see if the button is still held down the during the duration of this process, otherwise you could press the button then wait 2 seconds and press it again, and it will return true. You should have it check to see if the button is held down and if it is not, reset the timer back to 0.
651  Using Arduino / Project Guidance / Re: Displaying two analog gauges onto an LCD screen. on: June 10, 2014, 01:15:34 pm
Go to the Other Software Development section, and look for my name. I made the gauge into a library called TFT_Extension.

Link to page HERE
652  Using Arduino / Project Guidance / Re: really need help guys ... my graduation project :( on: June 09, 2014, 03:44:31 pm
Basically position triangulation.

all 4 Xbee modules and they should replay with the RSSI value and their own coordinates (( that we already give it to each one of them by the GPS ))

Actually all you would need to do is have the unknown device send a dummy variable to each of the four Xbee modules and time how long it takes to send and receive that variable back.

This is not exactly easy, because you need to convert the time to a distance, so you need to find that constant.
653  Using Arduino / Displays / Re: Arduino Mega + LCD on: June 09, 2014, 12:53:13 pm
While it is confusingly packaged, the library is the standard Henning Karlsen  and there is only one of them.
This is actually not true, venders who sell on ebay and other such sites, are distributing modified versions of Karlsen's libraries. I have one of those "fake" LCD screens that only works with Karlsen's older ITDB02 libraries. I even dug into both of them(fake and orig) to see just what was changed and found out that the registers for the data bus lines were changed. Some lines were taken out and added in.

I brought it to Karlsens attention and he is not happy at all, but he himself already knew that people were distributing fake versions.

Im thinking the OP has the original library(currently) but his screen might be set to only work with a modified library.

654  Using Arduino / Displays / Re: Arduino Mega + LCD on: June 09, 2014, 09:42:40 am
its most likely the library doesn't work for that screen, have you tried downloading the actual UTFT and UTouch libraries from Henning's website?
655  Using Arduino / Displays / Re: Arduino Mega + LCD on: June 09, 2014, 08:22:03 am
What library(s) are you using?
656  Using Arduino / Programming Questions / Re: Use of LCD 16x2 and Keypad 3x4, use of array of struct and string. on: June 08, 2014, 10:39:32 pm
There is a sticky post in bold orange, in the main screen, please read it. Code tags are a MUST, please highlite your code and click the # symbol above the smiley faces.

Also why is your lcd sharing the same pins as your keypad?
657  Using Arduino / Programming Questions / Re: 'void' function as a 'if' variable on: June 08, 2014, 11:52:17 am
I wanted to expand it, so Junblud could see what was happening.
658  Using Arduino / Programming Questions / Re: 'void' function as a 'if' variable on: June 08, 2014, 11:20:29 am
If the function returns something then yea, but not as a void or the way you have it.

void setup()

  for( byte idx = 0; idx < 10; idx++)
    Serial.print("At index: "); Serial.print(idx);
    if( foo( idx ) == true)
      Serial.println(", it was TRUE");
      Serial.println(", it was FALSE");

void loop() {/* not being used */ }

boolean foo(byte x)
  if(x > 4 && x < 7)
    return true;
    return false;
659  Using Arduino / Project Guidance / Re: Phantom reads into a 4051 on: June 08, 2014, 01:39:12 am
I'm willing to bet you don't have any pulling resistors (pull up or pull down) in which case the pin is considered floating. But as Raschemmel suggested, you should post a schematic or photo.
660  Using Arduino / Programming Questions / Re: If else statement for two pots and two LED's on: June 07, 2014, 11:15:37 pm
One other thing, when using the Serial monitor, you should not be using pins 0 or 1,
const int LED1 = 1;
Pages: 1 ... 42 43 [44] 45 46 ... 253