| Arduino Forum ::  Members :: s-light
 Show Posts Pages: 1 ... 3 4 [5] 6
 61 Using Arduino / Programming Questions / Re: struct and arrray size on: June 22, 2012, 04:30:47 pm ok thanks majenko!i will define a maximal for my use case!
 62 Using Arduino / Programming Questions / struct and arrray size on: June 22, 2012, 03:28:52 pm Hey @all,i would love to know how to set up a struct with some arrays.the challenging is, that the array size is not know.The Idea is as following:there is this really cool MultiMap function (http://arduino.cc/playground/Main/MultiMap)and my idea was to build a struct that holds all needed things for a nice mapping:Code:struct sMultiMapStruct { word mm_In []; word mm_Out []; byte size; }; typedef struct sMultiMapStruct tmm;for testing:Code:/****************************************************************************************************  *   structTest sketch  *     *     *   Created:  22.06.2012  *   copyright by Stefan Krueger  *   written by Stefan Krueger stefan@s-light.eu  *     *   Last modified: 22.06.2012 21:00  *   By Stefan Krueger  *   stefan@s-light.eu  *     *   changelog / history :  *  *****************************************************************************************************/struct sMultiMapStruct{ word mm_In []; word mm_Out []; byte size;};typedef struct sMultiMapStruct multiMap_type;multiMap_type mmMyMap = { {  0, 20,  30}, {  0, 80, 100}, 3};/**  * MultiMap  * http://arduino.cc/playground/Main/MultiMap  *  modified for 16bit word datatype  **/word multiMap(word val, word* _in, word* _out, uint8_t size){  // take care the value is within range  // val = constrain(val, _in[0], _in[size-1]);  if (val <= _in[0]) return _out[0];  if (val >= _in[size-1]) return _out[size-1];  // search right interval  uint8_t pos = 1;  // _in[0] allready tested  while(val > _in[pos]) pos++;  // this will handle all exact "points" in the _in array  if (val == _in[pos]) return _out[pos];  // interpolate in the right segment for the rest  return map(val, _in[pos-1], _in[pos], _out[pos-1], _out[pos]);}/**  struct sMultiMapStruct used so you need no headerfile for struct definition **/word mapIt(word wInputValue, struct sMultiMapStruct* mmTheMap){ // '(*mmTheMap).mm_In' could be also written as 'mmTheMap->mm_In' return multiMap(wInputValue, (*mmTheMap).mm_In, (*mmTheMap).mm_Out, (*mmTheMap).size);} /***************************************************************************************************/void setup()  { /**************************************************/ /* Welcom @ This Sketch!!                         */ /**************************************************/ Serial.begin(115200); Serial.println(); Serial.println("       "); Serial.println("   oo  "); Serial.println("  (  ) "); Serial.println("   ^^  "); Serial.println(); Serial.println("Welcome to structTest Sketch!"); Serial.println("system is starting!"); Serial.println(":-)"); Serial.println("");}void loop(){ for ( word x = 0; x < 30; x++) { Serial.print(x); Serial.print("-->"); Serial.println(mapIt(x, &mmMyMap )); //delay(10); if ( x == 20 ) { Serial.println("*** 20 ***"); delay(100); } } Serial.println(); delay(500); Serial.println("**************************************"); delay(500); Serial.println(); delay(500); Serial.println("**************************************"); delay(500); Serial.println(); delay(500); Serial.println("**************************************"); delay(500); Serial.println();}(now the problem is - i try to setup the size of the arrays at declaration of the variable.error:Code:structTest:32: error: too many initializers for 'word [0]'structTest:32: error: too many initializers for 'word [0]'is there some easy possibilities to do this an other way?sunny greetingsstefan
 63 Using Arduino / Project Guidance / Re: BPM Counter / Metronome for triggering a DMX console - need a little help on: June 18, 2012, 03:24:15 pm Hi Helmuth,i have not read the hole code.but here are some ideas about timing:lcds uses normally 'really much time' :-)and also float calculation is slow:Reference:FloatQuote from: Arduino Reference - FloatFloating point math is also much slower than integer math in performing calculations, so should be avoided if, for example, a loop has to run at top speed for a critical timing function. Programmers often go to some lengths to convert floating point calculations to integer math to increase speed. as example - if you need some accuracy like 1.3 you can use 13 as int and know that you have to divide by 10...so in the last step before printing it on serial or lcd you can print the right value :13/10 = 1  ( 13 divided by 10 in integer math gives 1)            .13%10 = 3  ( 13 modulo 10 (the rest of the division) is 3)it would help if you just write up a smal overview about how you think it should work - something like an 'flowchart' then it is faster for others to look through the code.just write something like:read input of Pushbutton1count upwrite lcd message - status - name of the daymake a tone...its just an idea- i will look into your code in the next days- some general thing - you could give your variables some cleaner naming scheme:i name them something like this:Code:// Pin Definitionsbyte pin_PushButton_Up = 1;byte pin_PushButton_Down = 2;byte pin_LightSensor = A1;// Light Sensorword wLightSensor_Raw = 0;word wLightSensor_Filtert = 0;// PushButton Statesbyte bPushButton_State_Up = 0; // is > 1 if Button is Active; is >2 if Button is Pressed a long timebyte bPushButton_State_Down = 0; // is > 1 if Button is Active; is >2 if Button is Pressed a long timeand hey - thats just how i like it^^there will be others that hate so long variable names ;-)i think there will be some nice 'code style guides' out there in the net..for me its easy to understand what i can do with the thing i just ride down..sunny greetingsstefan
 64 Using Arduino / Programming Questions / Re: library: const declaration how to do right? on: June 17, 2012, 06:42:03 am the idea was to define all things const that can not change -so that the compiler could do some cleanup or something like this..so if i mark the constructor arguments as const nothing changes in the errors.Code:MotorFaderControl::MotorFaderControl( const byte cbPin_ServoTrack, const byte cbPin_Direction, const byte cbPin_Speed, const byte cbPin_Break)is it the wrong way to declare the members constant?and yes the 'error: assignment of read-only data-member 'MotorFaderControl::xxx' is clear - but i dont know how to set the 'const' in an other way...i hope my approach is clear?!