Show Posts
Pages: 1 ... 16 17 [18] 19 20 ... 233
256  Using Arduino / Programming Questions / Re: Convert amount received by the serial on: June 20, 2014, 09:13:52 pm
Technically it holds up to the simplest method, because regardless of what comes in, its going to get converted to an integer (or some form of an integer).

However, as Peter said it would be a good idea to check if what came in was actually a decimal, which would then require a little more though and so it would then be a simple method.

Code:
if(Serial.available() > 0)
  {
     char serial = Serial.read();
     if( serial >= '0' || serial <= '9' ) // only digits get converted
        temp = (temp * 10) + (serial - '0');
  }

@Gillard
Note: once the integer is used for it's purpose, it is best to set it back to zero
257  Using Arduino / Programming Questions / Re: Convert amount received by the serial on: June 20, 2014, 08:00:03 pm
The simplest method is
Code:
int temp = 0; // global variable

void loop()
{
  if(Serial.available() > 0)
  {
     char serial = Serial.read();
     temp = (temp * 10) + (serial - '0');
  }
/* . . . other stuff */
}
258  Using Arduino / Programming Questions / Re: Can the (if statement) have A counter on it? on: June 20, 2014, 03:45:06 pm
Have a second counter "cnt" keep track of the high to low transition and if cnt is greater than 10, then stop changing the state.
if(cnt <= 10)
{
.
.
.
}
259  Using Arduino / Programming Questions / Re: Getting a steady output on a 1602 LCD display on: June 20, 2014, 03:03:46 pm
The print function should be inside the IF statement.
Code:
if(outputOld!=outputL){
    outputOld = outputL;
    printBinary16(outputOld);
  }
260  Using Arduino / Programming Questions / Re: Problem with my code,HELP! on: June 20, 2014, 02:16:05 pm
What is it doing and not doing?

Added:
This here is no good. There is a library called NewPing, it is far better and more precise than the old style like your using. It should make things much easier for you.
261  Using Arduino / Programming Questions / Re: Why do I get stange value from this calculation ? on: June 20, 2014, 02:11:27 pm
Have you tried this too?
Code:
UPONT * (float(Vcc) /1024.0) * ( (float(R1_kOhm + R2_kOhm)/float(R2_kOhm)) * 1000.0);
262  Using Arduino / Programming Questions / Re: Incomprehensible serial monitor outputs after running this code. on: June 20, 2014, 01:47:48 pm
What is the baud rate in the code and serial monitor?
263  Using Arduino / Programming Questions / Re: Getting a steady output on a 1602 LCD display on: June 20, 2014, 01:16:18 pm
The library is no good, we can give you the code to add the delay in properly, but in the end, even that may not work.

EDIT:
The thing is, in the code I gave you, I added basically a lockout condition. This lockout checks to see if the data is the same or if it has changed and if it is different then it shows it. But even that did not work.


What needs to be printed, where and duration.
264  Using Arduino / Programming Questions / Re: Arduino Won't Change EEPROM Setting. on: June 20, 2014, 09:18:32 am
Quote
I wonder why the script compiled with the missing second equal sign.
Because the compiler doesn't see it as being wrong, it sees the one equal sign and "thinks" you want to assign 1 to the variable x, when what you really want to do is compare them.
265  Using Arduino / Programming Questions / Re: need help in my programe . on: June 19, 2014, 08:51:35 pm
What values does it print to the serial monitor when you first turn it on?
266  Using Arduino / Programming Questions / Re: Getting a steady output on a 1602 LCD display on: June 19, 2014, 04:27:32 pm
Put a 1 second delay in the function, and see if it still blinks
267  Using Arduino / Programming Questions / Re: incrementally declaring variables on: June 19, 2014, 08:16:42 am
Pyro is correct, it won't work the way I said.

I tested it with an online simulator.
Code:
#include <iostream>

using namespace std;
#define SIZE(x) (sizeof(x)/sizeof(x[0]))

int array[] = { 25,84,36,95,1};
void printArray(int Arr[]);


int main()
{
   cout << SIZE(array) << endl;
   printArray(array);
  
   return 0;
}

void printArray(int * Arr)
{
   for(int i = 0, j = SIZE(Arr); i < j; i++)
   {
    cout << Arr[i]<< endl;
   }
}

Output:
Quote
Executing the program....
$demo
5
25
84

However with this, I got the following.
Code:
#include <iostream>

using namespace std;
#define SIZE(x) (sizeof(x)/sizeof(x[0]))

int array[] = { 25,84,36,95,1};
void printArray(int size, int * Arr);

int main()
{
   cout << SIZE(array) << endl;
   printArray(SIZE(array), array);
  
   return 0;
}

void printArray(int _size, int * Arr)
{
   for(int i = 0; i < _size; i++)
   {
    cout << Arr[i]<< endl;
   }
}

Output:
Quote
Executing the program....
$demo
5
25
84
36
95
1
268  Using Arduino / Project Guidance / Re: LCD menu's on: June 19, 2014, 06:27:50 am
Yea, but the way you showed, looked like you wanted the button to do different things when pressed multiple times.
269  Using Arduino / Audio / Re: Can anyone recommend a voice recognition module? on: June 18, 2014, 10:38:34 pm
Its decent within a 1 foot distance, you just need I speak very clearly.
270  Using Arduino / Programming Questions / Re: Arduino Won't Change EEPROM Setting. on: June 18, 2014, 09:27:41 pm
In IF statements, to compare anything you use == not a single =. Tell me from that code, can you read from the EEPROM?
Pages: 1 ... 16 17 [18] 19 20 ... 233