Show Posts
Pages: 1 ... 37 38 [39] 40 41 ... 86
571  Using Arduino / Programming Questions / Re: Piezo Switch input Analog or Digital, and detection on: May 12, 2013, 02:33:39 am
The piezo generates a lot more than 2-4V. Here are some references for you to read:

This one has a comparator type output towards the end that may be what you are looing for.

More general on what happens when a piezo is pressed.
572  Using Arduino / LEDs and Multiplexing / Re: I'm lost and desperate. Need help with RGB's, 595 shifters, on: May 11, 2013, 07:12:13 am
On my site (link below in my signature) I have some sketches that drive seven segment displays using the 595 shifter.
573  Using Arduino / Programming Questions / Re: Help With TCS3200 Color Sensor (Understanding Output) on: May 06, 2013, 03:13:19 am
The output of the sensor is a frequency that is linearly proportional to the colour intensity. What you need to do is measure that frequency for R, G and B and then interpret what colour you have.

I wrote a library for this sensor and have a pdf as part of the distribution that explains how the sensor can be calibrated. It also has a few examples sketches, one of which is for calibration. If you are interested follow the link in my signature below.
574  Using Arduino / Programming Questions / Re: Blinking LED with two different delays using millis. on: May 06, 2013, 03:10:21 am
In my code repository (link below) there is a Multiblink example that uses a data table to define many LEDs at different frequencies and time intervals. The code is a bit complex, as it allows for very general things to happen, but you may be able to learn from it (or play with the LED patterns).
575  Using Arduino / Programming Questions / Re: Noob question regarding variable positioning in the sketch on: May 05, 2013, 05:56:43 am
long previousTime = 0;
long totalTime = (lightTime + nolightTime);

These should be unsigned. It probably isn't the problem but it will cause issues in the long run.

Here is your code with the if/else reformatted so they make sense to most people:
unsigned long previousfanTime = 0;
unsigned long lightTime = 1000;
unsigned long nolightTime = 500;
unsigned long fanTime1 = 2000;
unsigned long nofanTime1 = 1000;
//unsigned long fanTime2 = 1000;
//unsigned long nofanTime2 = 2000;
const int ledPin = 13;
const int light1 = 2;
const int fan = 3;
const int light2= 4;
const int valve = 5;
long previousTime = 0;
long totalTime = (lightTime + nolightTime);

// the setup routine runs once when you press reset:
void setup()
  pinMode(light1, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(light2, OUTPUT);
  pinMode(valve, OUTPUT);
  pinMode(fan, OUTPUT);
  digitalWrite(ledPin, HIGH);

// the loop routine runs over and over again forever:
void loop()
  unsigned long currentTime = millis();

  if (currentTime - previousTime < lightTime)//this is what happens while the light is on
    digitalWrite(ledPin, HIGH);

    if (currentTime - previousfanTime <= fanTime1)                                                  //si el tiempo actual es menor que el tiempo de encendido de ventilador
      //entonces encendido
      digitalWrite(fan, HIGH);
      digitalWrite(fan, LOW);                                                                         //si no apagado
    if (currentTime - previousfanTime > (fanTime1 + nofanTime1))                                    //if time is over the total fan cycle, the fan cycle restarts
      previousfanTime = currentTime;
  else // now we stablish the loop for the time interval between lightTime and lightTime+nolightTime
  //that is to say the complete cycle
    digitalWrite(ledPin, LOW);

  if (currentTime - previousTime >= totalTime)
    previousTime = currentTime;

  Serial.print("previousTime: ");
  Serial.print("currentTime: ");
  Serial.print("difference: ");
  Serial.println(currentTime - previousTime);

Check that the logic you have is correct. Also, is you could explain what this is supposed to do (ie, why you wrote the program) we can look at it with some context for this logic and make comments.
576  Using Arduino / Programming Questions / Re: how to run a loop n number of times on: May 05, 2013, 03:15:15 am
The syntax you gave is not 'while' but 'for'. While loop takes a boolean condition.
577  Using Arduino / Programming Questions / Re: how to run a loop n number of times on: May 05, 2013, 01:07:42 am
It all depends on what the experience is supposed to be.

If person1 is there, and person2 arrives, person 1 leave, person 2 is still there, and person 3 arrives before person2 leaves, etc, is the twitching supposed to happen again? What creates some interest in these sorts of displays is that the action happens when the person is detected and then it repeats after a little while if someone is still in front of the display. If not then it waits for the new person to arrive.

In this case the software is either in a state that is waiting for the sensor to trip, twitching or waiting for time to run out.

I guess it is totally dependent on what the OP wants to do, which is not clear from the info here.
578  Using Arduino / Programming Questions / Re: how to run a loop n number of times on: May 04, 2013, 01:00:15 am
Use a flag to set whether you are waiting for a person (sensor) or are waiting for some time to pass.

When you detect your person, use a for loop with the random number (for I=0; I<random number; i++) to twitch, then set a flag that enables the time code and disables the twitchy sensor code (use the if statement). Then wait for a period of time (look at the blink without delay example for how to do this or use delay() if you don't care about doing something else in between) after which you reset the flag and your twitchy code can run again.
579  Using Arduino / Programming Questions / Re: Calling functions from string on: May 03, 2013, 10:47:08 am
you'd probably want to offset the indices

This means that you make the zero element of the array the first character that you want to use, For example, if the character is 'A', then to use this as an offset you need to subtract the code for 'A' from the letters you are looking up, like
index = character - 'A';
array[index] is then the data you are after. IN this case this is the address of the function to call.

To set up the array
array[] = { functionA, functionB, etc };
just make sure that the functions are defined.

Calling the functions is a bit more complicated and you should look it up. AWOL gave you the search reference.

If you don't understand this method, then something like this may be easier for you.
switch (character)
case 'A': functionA(); break;
case 'B': functionB(); break;
580  Using Arduino / Programming Questions / Re: Calling functions from string on: May 03, 2013, 08:27:23 am
You cannot do this the way you are trying to do it. The function names need to be dereferenced by the compiler at compile time.

There are a number of different approaches:
1. You can set up an array of function pointers for each letter of the alphabet, then call the function based on the array lookup. This produces the most compact code.
2. Each letter can be in a switch/case statement and the function is called from the appropriate case. If you have only a few letters to handle this will probably use the least amount of memory
3. Use if statements, as in "if (letter == 'A') function_A();"
581  Using Arduino / Programming Questions / Re: how to ' convert data types to get only one decimal point ' ? on: May 01, 2013, 03:04:39 am
Riva probably has the easiest answer for you.

@ukhelibob - good question and I can't see an answer. Give other restrictions on floats, I expect probably not.

Update: here is a solution,146638.0.html
582  Using Arduino / Programming Questions / Re: how to ' convert data types to get only one decimal point ' ? on: May 01, 2013, 02:47:18 am
Use sprintf() to format the string before you use it, into a character array and then print the character array. There is an option to use a specific number of decimal points as part of the %format string (%.1f from memory, but better look it up).
583  Using Arduino / Programming Questions / Re: Count Down Code Options on: April 29, 2013, 02:24:28 pm
I have implemented something similar that counts down from 99 seconds that you could adapt. Look in the link below (signature block). Hope it is useful.
584  Using Arduino / Displays / Re: Does anyone know how to address character map of a 16x2 LCD? on: April 27, 2013, 06:49:12 pm
My reading of documentation has been that the LCD displays come with one rom set. Most of the ones I have seen have been the Asian extended characters. I have not found any way to 'switch' the rom code to one of the others sets - they are different part numbers from the manufacturer.
585  Using Arduino / Displays / Re: Does anyone how to address character map of a 16x2 LCD? on: April 27, 2013, 03:31:09 pm
As far as I know you just use the ASCII code for the characters and they will work. Internally they may well be arranged as rows and columns, but that is too detailed for me to want to worry about when I am just trying to print a character.
Pages: 1 ... 37 38 [39] 40 41 ... 86