| Arduino Forum ::  Members :: marco_c
 Show Posts Pages: 1 ... 26 27 [28] 29 30 ... 75
 406 Using Arduino / Programming Questions / Re: Rounding sensor values down to 2 decimal places on: May 30, 2013, 09:40:15 pm One (convoluted) way is to multiply by 100 (or 10^x where x is the number of decimal points you need), cast it to an int or long, then assign it back to a float and divide by 10^x.eg, using 10.987* 100 = 1098.7to int 1098to float 1098.0/100 = 10.98If you just need conversion when the number is printed you can specify that in the print statement.
 407 Using Arduino / Storage / Re: Averaging Array on: May 30, 2013, 09:32:58 pm If you are just looking for the average value every five minutes (ie, not a running average of the *last* five minutes), you can do that without an array.You need 2 variables - the current average and the number of values read so far.1. Initialise the average to the first value in the time period, set the count = 12. Every other value that arrives is added as follows: average = ((old_average * count) + current_value)/(count+1); 3. count = count+1At the end of your period use the avarage, reset the counters and start again.Running average over the last five minutes is a different story and will need some form of storage.
 408 Using Arduino / Programming Questions / Re: creating function that blink led by number of my choice on: May 26, 2013, 10:19:18 pm Code:void blinkred( char c_Pin, char c_Count  )would Code:void blinkred( uint8_t u_Pin, uint8_t U_Count  )be better style?For me it is clearer that we are dealing with an unsigned number and not a character (even if the result may be the same).
 409 Using Arduino / Programming Questions / Re: |= please help! on: May 18, 2013, 12:21:31 am A |= B is the same as A = A|BYou can use the same for all the other operators (+=, *=, /=, %=, you get the idea). It is just a shorthand, just as A++ is the same as A+=1 or A=A+1.
 410 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:1. http://www.scienceprog.com/thoughts-on-interfacing-piezo-vibration-sensor/This one has a comparator type output towards the end that may be what you are looing for.2. http://leucos.lstilde.org/wp/2009/06/piezo-transducer-signal-conditioning/More general on what happens when a piezo is pressed.
 411 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.
 412 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.
 413 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).
 414 Using Arduino / Programming Questions / Re: Noob question regarding variable positioning in the sketch on: May 05, 2013, 05:56:43 am Code: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:Code: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() {                  Serial.begin(9600);  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);    }    else     {      digitalWrite(fan, LOW);                                                                         //si no apagado    }    //end     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.println(previousTime);  Serial.print("currentTime: ");  Serial.println(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.
 415 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.
 416 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.
 417 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
 418 Using Arduino / Programming Questions / Re: Calling functions from string on: May 03, 2013, 10:47:08 am Quoteyou'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 Code: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 Code: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.Code:switch (character){case 'A': functionA(); break;case 'B': functionB(); break;etc.}
 419 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 memory3. Use if statements, as in "if (letter == 'A') function_A();"
 420 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 http://arduino.cc/forum/index.php/topic,146638.0.html
 Pages: 1 ... 26 27 [28] 29 30 ... 75