Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 236
61  Using Arduino / Programming Questions / Re: My first program. on: April 19, 2014, 07:50:49 am
You presumably had something in mind when using
Code:
void loop(13)
What was it ?
62  Using Arduino / Programming Questions / Re: if else or switch case? on: April 19, 2014, 02:23:57 am
Quote
i have about 25 if else statements, i was wondering if there would be any advantage of using switch case statements
Personally I find switch/case much easier to read and maintain, particularly if you use suitably named constants for the cases, but it is up to you.

I would hope that the compiler turns out similar efficient code for both if/else and switch/case.  You don't say what your application is doing but does absolute speed matter ?
63  Using Arduino / Programming Questions / Re: Is a while loop embedded in if/else if legal? on: April 19, 2014, 02:10:00 am
Quote
Each digit could have a different color and would need to be tested after each random generation until a suitable new color for all 2 or 3 digits is found.
Test the colour of each digit individually.
Code:
while (lastColor_2 == newColor_2)
{
   newColor_2 = random(11);
}
I will say it before anyone else does.  There is a much neater way of doing this using arrays to avoid repeating code for each digit but I suggest that you get the tedious 'do each number separately' method working first.
64  Using Arduino / Programming Questions / Re: Problem: UDP Wraped with If Statement on: April 18, 2014, 04:28:05 pm
What do you mean by 'stops working' ?
What do you see if you print the value of e just after the test of the value of v1 inside the for loop, and before the if after the for loop ?

Note that e will always be 1 if the 16th reading of v1 is zero no matter what the previous 15 readings were.  Is that what you intended ?
65  Using Arduino / Programming Questions / Re: LED fading with for loop on: April 18, 2014, 04:16:12 pm
Code:
while(1){
  for(a=0;a<=255;a=a+10);
  for(a=255;a>=0;a=a-10);
  }
This while loop never ends and even if it did all the for loops do is to make a go from 0 to 255 then back down to zero again over and over again.  The value of a is never even used as the while loop never ends.

There is no need for a while loop because the loop() function repeats anyway as the comment says.  Take it out along with one of the for loops, change the order of the code and remove the semi-colon from the end of the for loop line, tidy up the code to make it easier to read and you get
Code:
void loop() 
{
  for(a = 255; a >= 0; a = a - 10)
  {
     // set the brightness of pin 9:
     analogWrite(9, a);   
    // wait for 30 milliseconds to see the dimming effect   
    delay(30);                           
  }
}
66  Using Arduino / Programming Questions / Re: Expected Initializer before 'int' Error on: April 18, 2014, 12:35:11 pm
Nothing much wrong then ........
67  Using Arduino / Programming Questions / Re: Is a while loop embedded in if/else if legal? on: April 18, 2014, 12:34:13 pm
It is 'legal' but this while loop
Code:
  while (lastColor_8 == randNumber && lastColor_2 == randNumber)  //BINARY 8 & 2
    {
   randNumber = random(11);  // Generate a new (color) randNumber
    }
will do nothing unless lastColor_8 and lastColor_2 both happen to equal the already existing value of randNumber when it starts, and even then it will end almost immediately because the condition will become false in most cases straight away.

Can you explain what it is supposed to do and how ?
68  Using Arduino / Programming Questions / Re: Expected Initializer before 'int' Error on: April 18, 2014, 11:42:38 am
Code:
  for(int i=0; i< 3; i++);
Remove the semi-colon at the end
69  Using Arduino / Programming Questions / Re: New to arduino need some assistance on: April 18, 2014, 11:31:47 am
What do you want the program to do ?
Code:
if something is true
  carry out action 1
end of if
else
  carry out action 2
end of else
What is the something that can be true or false ?
What are actions 1 and 2 ?
70  Using Arduino / Project Guidance / Re: void loop() 1 void loop() 2 on: April 18, 2014, 08:47:02 am
It refers to an example program in the IDE.
The technique that it uses involves noting a start time then checking periodically to see whether a time interval has passed.  If yes then react to it, if not the go and do something else such as checking whether another timing period has elapsed.  

Unlike using the delay() function the program does not stall whilst the delay happens, so that the Arduino can appear to do 2 (or more) things at the same time.
71  Using Arduino / Programming Questions / Re: Midi Serial, Pin Selection on: April 18, 2014, 07:48:59 am
Have a look at the MIDI_Bench example which comes with the library to see how to use SoftwareSerial with the library which leaves hardware serial free for other purposes.

Code:
SoftwareSerial midiSerial(2,3);
MIDI_CREATE_INSTANCE(SoftwareSerial, midiSerial, softMidi);
72  Using Arduino / Programming Questions / Re: Howe can I get a button to start a RF 433MHz transmitter to send a message? on: April 18, 2014, 06:14:40 am
Do you really mean remote control or do you mean a wired switch or button ?
73  Using Arduino / Programming Questions / Re: Reading and writing to the same Arduino Pin on: April 18, 2014, 06:12:04 am
Quote
What I want to do is check if the Digital pin is High and keep it high till the temperature falls below the set temperature.
Why do you need to test the state of the pin ?  You set its state so you know what it is already.   It will not go LOW unless/until your program sets it LOW.
74  Using Arduino / Programming Questions / Re: gsm SimpleWriteln not working... HELP! on: April 18, 2014, 04:51:39 am
When you say it does not work what do you mean exactly ?
75  Using Arduino / Programming Questions / Re: Servo project help! on: April 17, 2014, 12:56:41 am
Or you might like to use the more obvious
Code:
pinMode(pushbutton, INPUT_PULLUP);
This ensures that the input pin is held at a known state (HIGH) at all times until pressing the button takes it LOW.  Obviously the wiring and the program logic need to match the HIGH/LOW off/on state of the button.
Pages: 1 ... 3 4 [5] 6 7 ... 236