Show Posts
Pages: [1] 2 3 ... 14
1  Using Arduino / Programming Questions / Re: Arduino variables on: June 13, 2014, 08:54:24 am
I see you have:
   if(precedente == 0){
    if(precedente == 1) {

and then:
void on(){
  digitalWrite(2, HIGH);
  precedente = 1;
void off(){
  digitalWrite(2, LOW);
  precedente = 0;

This expands to:
   if(precedente == 0){
      // code for on() function
      digitalWrite(2, HIGH);
      precedente = 1;
    // at this point, precedente cannot be 0 (think about it!)
    if(precedente == 1) {
      // code for off() function
      digitalWrite(2, LOW);
      precedente = 0;

2  Using Arduino / Programming Questions / Re: My Clock is Losing Time... on: March 23, 2014, 01:56:33 am
// *** Time Zone
const int timeZone = -7;  // Pacific Daylight Time (USA)
// *** DST Offset Toggle
const int timeDST = 1;  // 1 = DST ON / 0 = DST OFF

It looks like the problem is that you are compensating for Daylight Saving Time twice instead of just once.
You are using: -7 + 1 = -6
I think you want: -8 + 1 = -7
3  Using Arduino / Programming Questions / Re: format and print float numbers without String on: February 17, 2014, 11:12:21 pm
Why "float numbers"?

Use casting and arithmetic so you're dealing only with integers.
Something like this:

float x = 123.45; // this is the number you want to display

float xabs = x;
char xsign = '+';
if (xabs < 0) {
  // take care of negative numbers
  xabs = 0.0 - xabs;
  xsign = '-';
// at this point:
// xabs is the absolute value of x
// xsign is the sign of x, either '+' or '-'
unsigned int xwhole = (int) xabs;
byte xcent = (byte)((xabs - xwhole) * 100 + 0.5);
if (xcent > 99) {
  xcent = 0;
// at this point:
// xsign is the sign of x, either '+' or '-'
// xwhole is the whole number part of x
// xcent is the "hundredths" part of x

// for example:
// if x is 123.45, then xsign will be '+',
// xwhole will be 123, and xcent will be 45

// another example:
// if x is -8.09, then xsign will be '-',
// xwhole will be 8, and xcent will be 9
Once you split the floating-point number into sign, integer part, and fractional part, then you can display these parts by other means.
4  Using Arduino / Project Guidance / Re: solar tracker using RTC on: February 17, 2014, 11:17:29 am
Seems no one has much hope for a poor Uno or similar to handle the sun tracker algorithm

What algorithm? You don't need an algorithm.

Look at the picture at this link:
More info here:

Look at carefully at the pictures of the sundials, and try thinking about this matter with your right brain.
5  Using Arduino / Project Guidance / Re: Math operators, decimals and float on: February 16, 2014, 07:37:27 am
You can write your own function but I don't know how fast it will be.

To what precision do you want the logarithms?
6  Using Arduino / Programming Questions / Re: Code for logarithmic volume control on: January 24, 2014, 05:19:52 pm
From what I gather, a "logarithmic" volume control is not really logarithmic but exponential.

You could use a pow() or exp() function, but if I were you, I would just make my own such function.
7  Using Arduino / Programming Questions / Re: Maths precision for Arduino? on: January 22, 2014, 03:24:32 pm
How about this?
8  Using Arduino / Programming Questions / Re: Convert float to char on: January 04, 2014, 10:48:36 pm
Don't mess with this FormatDouble if you can help it.

Instead, you could use something like this:
char dtTempF_sign;
int dtTempF_whole;
int dtTempF_tenths;
char dtTempF_string[8];
if (dtTempF < 0.0) {
  // negative temperatures
  dtTempF_sign = '-';
  // convert to tenths of a degree
  dtTempF_tenths = (int)((-dtTempF * 10.0) + 0.5);
else {
  // zero or positive temperatures
  dtTempF_sign = ' ';
  // convert to tenths of a degree
  dtTempF_tenths = (int)((dtTempF * 10.0) + 0.5);
// split temperature into whole number and tenths
int dtTempF_whole = dtTempF_tenths / 10;
dtTempF_tenths = dtTempF_tenths - (10 * dtTempF_whole);

// convert to string
sprintf_P(dtTempF_string, PSTR("%c%d.%d "),
 dtTempF_sign, dtTempF_whole, dtTempF_tenths);

I hope that this use of sprintf_P doesn't hurt your memory usage too much.
Even if it does, I've shown you how to split a temperature into sign (minus for negative or blank for positive), whole degrees, and tenths of a degree: you could use other formatting functions (or even direct manipulation of individual characters) to get exactly what you want.

9  Using Arduino / Programming Questions / Re: !!! Push Button Counter !!! EASY ANSWER PLEASE HELP on: January 04, 2014, 10:19:23 pm
Do I need to debounce the button, when I pushed the button it counted 0,3,6, instead of 0,1,2.
Yes. No. Maybe. Who knows? Only YOU can see your code.
Why so much snarkiness on these forums?

Short answer: in general, it is wise to debounce buttons.
The "lazy" way to debounce a button is to wait a few milliseconds after the button changes state (on to off, or vice versa) before the next time you read it. For many purposes (such as that of a sports scoreboard), using a statement like
will suffice.

By the way, displaying your scores in binary (if you don't know what binary is, look it up) will be easier to build, but harder to read. I suggest putting together a binary version of the scoreboard, and then once you've got that right, looking up how to use a 7-segment display.
10  Using Arduino / Project Guidance / Re: Math Arcade Game Guidance on: January 03, 2014, 07:11:34 am

Just make sure that, before you let the students at it, you have tested the machine to make sure everything is working -- including printing some practice tests, solving them yourself (deliberately including a "mistake" or two just to make sure the machine recognizes mistakes), and then using the machine to check the answers.
11  Using Arduino / Project Guidance / Re: TimeLord? on: January 03, 2014, 07:08:13 am
I wonder how much processing power, not to mention RAM, it chews up.

Maybe better just to hard-code a lookup table based on month, and interpolate / extrapolate based on the day within the month.
12  Using Arduino / Programming Questions / Re: Atomic reading of uint16_t ? on: January 03, 2014, 07:04:23 am
Can you make the counter in to two 8 bit values thus:

  uint8 high = counterHigh;
  uint8  low = counterLow;

  return (uint16)  ((high<<8) | low) ;
Um... wrong. You need to cast high before shifting it so far left.
13  Using Arduino / Programming Questions / Re: Atomic reading of uint16_t ? on: January 03, 2014, 12:27:55 am
Does this counter really need to have more than 8 bits?

If this counter increases by no more than 10 each time through loop(), then why not just have the counter be 8 bits, and have loop() check for overflow?
14  Using Arduino / Programming Questions / Re: Convert int to byte array on: January 02, 2014, 12:07:16 pm
digit = ((originalNumber/(10^segSetup))%10);

It's a good thing that this got commented out and replaced.

In C++ (and the Arduino programming language is just glorified C++), the ^ symbol does not stand for exponentiation.
In fact, there is no built-in function for integer exponentiation. You have to write your own, using a loop or some such.
15  Using Arduino / Project Guidance / Re: Math Arcade Game Guidance on: January 01, 2014, 11:35:39 pm
This entire issue can be sidestepped by using a pseudorandom number generator to generate the questions, and seeding the generator with the quiz number.
Pages: [1] 2 3 ... 14