Show Posts
|
|
Pages: 1 [2]
|
|
18
|
Using Arduino / Programming Questions / Re: Can someone help me compact and clean up this code.
|
on: August 19, 2012, 06:42:08 am
|
|
Try using arrays rather than having 5 similar named variables.
eg. #DEFINE ARRAYSIZE 5 int Finger[ARRAYSIZE]= {0,1,2,3,4};
byte servoValue[ARRAYSIZE];
Then you can loop over the array rather than having multiple lines with just slightly different variable names.
for (byte loopCount =0; loopCount < ARRAYSIZE; loopCount++) { servoValue[loopCount] = Function(FInger[loopCount]); }
It will also help you spot all those unused variables. It is much easier to declare all the variables at the start of apiece of code rather than some at the start and some part way through.
Edit - OK Tom beat me to it but the same idea.
|
|
|
|
|
19
|
Using Arduino / Sensors / Re: Massive sensor noise/problems?
|
on: August 16, 2012, 04:28:20 pm
|
|
Are you sure the line MagX = Wire.read()<<8; //X msb is working as you expect. The byte needs to be cast to an int, is this done before the shift or after? If before the cast then the values you are getting will all be zero. Might be worth putting a debug line in to check the values read for MagX make sense (also MagY and Z)
|
|
|
|
|
21
|
Using Arduino / Sensors / Re: Massive sensor noise/problems?
|
on: August 13, 2012, 08:48:52 am
|
|
When you only show two pieces of code that don't appear to have the error in it makes it very difficult to guess what he problem is - try posting ALL the code!
Are you sure you're reading the values in the same order you are writing them?
|
|
|
|
|
22
|
Using Arduino / Programming Questions / Re: For-Loop Questions and a Complex Biped
|
on: August 13, 2012, 03:38:28 am
|
|
You need to post the whole code, especially if you are wanting to keep values in variables where teh definition of those variables and the location cannot be seen. It may be that you want to define them as static, or make them global, or defined at a differerent context.
|
|
|
|
|
27
|
Using Arduino / Storage / Re: help me. Arduino with eeprom AT24c01
|
on: July 26, 2012, 06:21:21 am
|
Youare writing to add1 in both loops of your code, so the second loop overwrites the contents written by the first loop and the second address will be blank. Try altering your code to for(int i = 0; i < 16; i++) { Wire.beginTransmission(add1); Wire.send(i); Wire.send(dataku1[i]); Wire.endTransmission(); delay(100); } Serial.println("Write EEPROM 2"); for(int i = 0; i < 16; i++) { Wire.beginTransmission(add2); //Previously add1 Wire.send(i); Wire.send(dataku2[i]); Wire.endTransmission(); delay(100);
|
|
|
|
|
28
|
Using Arduino / Storage / Re: Problem reading SD card high bytes
|
on: July 17, 2012, 08:22:40 am
|
|
2730 * 12 = 32760 which is the highest value you can get below 32767. 32767 being the highest value in a 16bit unsigned integer.
If you want to go further than record 2730 you will need to use a datatype larger than 16bit surely?
|
|
|
|
|