| Arduino Forum ::  Members :: dafid
 Show Posts Pages: 1 [2] 3 4 ... 8
 16 Using Arduino / Programming Questions / Re: boolean If statements not working. on: March 13, 2011, 05:14:25 am I can not find 'IRremote.h' in the arduino site...Where did you find it?Thanks
 17 Using Arduino / Programming Questions / Re: Code Help with driving motors on: March 13, 2011, 04:59:37 am I am way late to notice this. Sorry .  I hope you moved on:)
 18 Using Arduino / Programming Questions / Re: unexpected result with millis on: March 12, 2011, 03:35:53 pm Once it is data driven..it is easy to change the logic..Quote from: Nick Gammon on March 11, 2011, 05:24:06 amYou realize, I suppose, that the "%" is the modulus operator. That is, the remainder after a division. Now a division is one of the slowest bits of arithmetic you can do (try it in your head if you don't believe me).  And you are asking it to do 76 divisions every 1/1000 of a second.....A quick test shows that an Arduino Mega 2560 takes 3.34 milliseconds to do a single batch of 76 modulus operations on an unsigned long. Test:So it is completely impossible for your sketch to work, if you are relying on the loop being executed once every millisecond. You need to find a more efficient way of doing it. For example, don't do a modulus, but work on intervals.To address Nicks comment about % being slow, the % is replaced in loop() with additions and comparisons..This is what was meant by using 'intervals' in some of the earlier posts.Code:// defines the intervals for each pin// on is % the interval, of is % interval+1// the pin is not changed if the interval is 0.unsigned int interval[41] = { 0, // index 0 not used, just to align pin numbers to array indexes. //1 1000, 1100, 900, 1200, 2000, 1500, 990, 550, 600, 500, // 11 (12 not used) 600, 0, 950, 800, 700, 850, 550, 300, 400, 300, // 21 (29 not used) 350, 200, 250, 320, 120, 500, 500, 500, 0, 500, // 31 500, 500, 500, 500, 500, 500, 500, 500, 150, 500} ;// records the next time the pin should be turned onunsigned long int nextOn[41] ;// records the next time the pin should be turned offunsigned long int nextOff[41] ;void setup(void){ int i; for (i=1; i <= 40; i++) pinMode(i, OUTPUT) ; unsigned long int time = millis() ;// for (i=1; i < 41; i++)  // This is not a mistake, but is inconsistent to the line above.// for (i=1; i <= 40; i++) { if (interval[i] != 0) { nextOn[i] = time + interval[i] - (time % interval[i]) ; nextOff[i] = time + interval[i]+1 - (time % (interval[i]+1)) ; } }}voidloop(void){ unsigned long int time = millis() ; byte i ;// for (i=1; i<= 41; i++) // ** MISTAKE** for (i=1; i <= 40; i++) { if (interval[i]) { if (nextOn[i] <= time) { nextOn[i] += interval[i] ; digitalWrite(i, HIGH) ; } if (nextOff[i] <= time) { nextOff[i] += interval[i]+1 ; digitalWrite(i, LOW) ; } } }}Of course there is still the question of whether the implemented algorithm is what you intended.As the the periods the switches remain on will over time vary between 0 ms and interval [ i ]+1 ms.
 19 Using Arduino / Programming Questions / Re: unexpected result with millis on: March 12, 2011, 03:26:50 pm This is a good place for data driven programming...This is your code expressed in that style...Code:// defines the intervals for each pin// on is % the interval, of is % interval+1// the pin is not changed if the interval is 0.unsigned int interval[41] = { 0, // index 0 not used, just to align pin numbers to array indexes. //1 1000, 1100, 900, 1200, 2000, 1500, 990, 550, 600, 500, // 11 (12 not used) 600, 0, 950, 800, 700, 850, 550, 300, 400, 300, // 21 (29 not used) 350, 200, 250, 320, 120, 500, 500, 500, 0, 500, // 31 500, 500, 500, 500, 500, 500, 500, 500, 150, 500} ;void setup(void){ int i; for (i=1; i <= 40; i++) pinMode(i, OUTPUT) ;}voidloop(void){ unsigned long int time = millis() ; byte i ;// for (i=1; i<= 41; i++) // ** MISTAKE** for (i=1; i <= 40; i++) { if (interval[i]) { if ((time % interval[i]) == 0) { digitalWrite(i, HIGH) ; } if ((time % (interval[i]+1)) == 0) { digitalWrite(i, LOW) ; } } }}
 20 Using Arduino / Programming Questions / Re: Managing IR detection&Beacon detection at high speed on: March 12, 2011, 01:54:11 pm Remember that you ask someone who does not know what the code drives to to give advice on how to fix the robot?First advice - describe the robot wiring and components... and how it connects to the arduino.However your code is also poorly documented.As code gets longer, the task of understanding the intent grows, perhaps much faster than the actual length.. unless the writer is careful.This code is moderate in length, but very difficult to understand because you have not documented it well.In general you should document the reason you are writing the code...In the case of a micro-controller controlling a motor using sensors, you should provide in the code the following information..- the expected range of values from the sensors.- the range of the motor controls, and their meaning.- for each define, the is a reason for it, as well as a name that reminds you of the reason- for each formula, the intention of it, and the reason the values are chosen.Then there are the variable names, they should be sensible, and relate to the problem.For example ir0, .. ir4  presumably are geometrically laid out on the robot.Something like if_Left, ir_Right, ir_Front, ir_Back would help.Then there are the magic pin numbers scan(11, 12, 13, 14) These should be defined and referred to by a name.After these sorts of issues are fixed the code will be easier to read, understand  and comment on.Sorry that I can not help you with your problem .
 21 Using Arduino / Programming Questions / Re: sketching to read 3 dof IMU combo board on: March 12, 2011, 12:11:26 pm The board (based on the Sparkfun IMU_Combo_Board-v2.pdf doc) produces analog voltages on each of the output pins..You need to wire the power leads between the arduino and the board;- gnd and +5v.Be careful that gnd is linked to gnd and 5v is linked to 5v.. Then pick one of the outputs and wire it to analog pin 0. (i would use 9 or 10 which are the acceleration sensors and will react as you tilt the sensor).And use the example sketch AnalogInput  (which you can find in the File-menu/examples).have fun
 22 Using Arduino / Programming Questions / Re: Communication with a mobile phone on: March 11, 2011, 12:41:37 pm Ok - dont know if you are still waiting for an answer here...
 23 Using Arduino / Programming Questions / Re: Interrupts pins issue on: March 10, 2011, 06:40:32 am has anything changed now? the schema makes sense I think- although having to scroll back to find it is odd- and having it change after it was posted tends to make reading the following comments difficult, as the refer to earlier versions of the schema.
 24 Using Arduino / Programming Questions / Re: Need help changing the Arduino as ISP sketch on: March 10, 2011, 06:27:42 am need more info?i have had those (or similar) errors for lots of dumb reasons..really need to check pretty much everything to be sure it is correct.
 25 Using Arduino / Programming Questions / Re: Comparing chars....? on: March 07, 2011, 03:44:27 pm You could convert them to a long..or as MarkT said.. you could match from left to right... Code:byte diff ;byte index ;for (index=0; index < 11; index++) // look at each character of the time strings{    diff = time[index] - now[index] ;    if (diff != 0)         break ; // stop at the first difference}if (diff == 0) // there where no differences{     // times are the same}else if (diff < 0) // the first difference was now[index] > time[index]{     // now > time}else if (diff > 0) // the first difference was now[index] < time[index]{     // now < time}
 26 Using Arduino / Programming Questions / Re: Pass an instance of an object into a constructor of another class on: March 06, 2011, 08:52:20 pm Was away..to understand this lineCode:holder (my_number & n): my_number (n) {};You need to see the class definition.. hope the comments helpCode:class holder {  // starts the definition of a class 'holder'    public:       // every thing in the class that follows is visible to the rest of the program      holder   // is a constructor - you ask about passing in a reference to the constructor..         ( my_number &n ) // the parameter of the constructor, this is the reference to the class that I am passing in - like you asked.         : // this is the special syntax that introduces the 'initialisers' for the class         m_n (n)  // this is the only initialiser - it sets the initial value of the member variable m_n to the reference passed in.                      // you have to do it this way, because a reference can only be set when it is initialised. it can not be changed afterwards.         {// the {} was just an empty body for the constructor.  You could have your code in here.          m_n.m_v++;                                // i added a line to make the number referred to 1 bigger.         } ; // i always put ';' in, but it is not required.     my_number &m_n;  // the member variable that is initialised to hold the reference (or address) of the class object passed in} ; // ends the definition.
 27 Using Arduino / Programming Questions / Re: Interrupts pins issue on: March 06, 2011, 11:31:16 am The schematic does not show motorpin (13), so I guess that the schematic is not complete?If nothing is plugged into the board, the input pin(18) is floating, unless you enable the internal pull up, which the code does not.So being interrupted continuously by falling edge seems reasonable in that case.try addingCode:digitalWrite(18, HIGH) ;  to the setup() function and see if the behaviour is better with the board is disconnected from the circuit.
 28 Using Arduino / Programming Questions / Re: Pass an instance of an object into a constructor of another class on: March 04, 2011, 05:51:59 pm Code:class my_number{  public:     my_number(int i) { m_v = i ; }     int m_v ;} ;class my_number n(10) ;class holder{  public:     holder(my_number &n) : m_n(n) {} ;          my_number & m_n ;} ;void setup(){class holder h(n) ;}void loop(){}
 29 Using Arduino / Programming Questions / Re: Pass an instance of an object into a constructor of another class on: March 04, 2011, 05:35:07 pm Wow, there is a lot of code there.And there still is not the lines of code showing the constructor definition of implementation.Maybe if you created a sketch that just showed the class definitions (both the class that holds a reference and the other class) and your constructors?Then checked to see if you get the same errors..It is a loteasier to understand a problem with a small example.
 30 Using Arduino / Programming Questions / Re: Communication with a mobile phone on: March 01, 2011, 06:54:03 pm please post your actual code, a description of what you want to achieve, and of what happens when you try.I only half guess that you believe you buggered up pins 1 & 2 ... not sure.I know the code below does no compile.. so it is not the code you use really.Copy it from the editor into a code entry (the button with a '#'  - 3rd last above the smilies)Use preview to see if it worked.Below is your code copied into a code block.Code:#include#define rxPin 11#define txPin 10NewSoftSerial mySerial(rxPin, txPin);const int Led_rouge = 8;void setup(){     pinMode(Led_rouge, OUTPUT);     mySerial.begin(9600);     mySeial.println("AT+CPIN=0409");}void loop(){    if(mySerial.available()){    digitalWrite(Led_rouge, HIGH);    }}
 Pages: 1 [2] 3 4 ... 8