Show Posts
Pages: 1 ... 90 91 [92] 93 94 ... 231
1366  Using Arduino / Programming Questions / Re: How to combine 2 codes? on: October 18, 2013, 08:50:43 am
If this is a personal project then why do you have a deadline ?  Take your time and follow the advice given by holmes4 and CrossRoads.
If this is a school assignment then there probably is a deadline but you are supposed to work out the solution for yourself, or at least try to.

In either case you need to define what the combined program should do.  They cannot just be combined with no more detail as to what is required.
1367  Using Arduino / Programming Questions / Re: Keypad command line programming on: October 18, 2013, 04:51:06 am
That sounds relatively easy, but it depends on your level of expertise.

Read the keypad output until the 'end of input' indicator (return) is received. 
As each character is read add it to an array of characters before reading the next one.
When the input is complete, parse the array to determine the LED to be set and the required level. 
Set the LED to the required level and go back to reading input.

Use an array of chars to hold the input not a String.

How much of the above do you understand ?
Have you successfully read single characters from the keypad and displayed them in the Serial monitor ?
1368  Using Arduino / Programming Questions / Re: arduino code help on: October 18, 2013, 04:38:08 am
Analog pins are INPUT only, so this is useless.
Paul, I suspect what you meant was that analogue pins cannot be used for analogue (PWM) output, but that is not how your post reads at first sight, hence the comments here to the contrary.

In practice is there any harm in setting the pinMode to OUTPUT for an analogue pin ?  It certainly acts as a reminder in the code as to what the pin is being used for.  Digital pins default to INPUT but it is common practice to set hem explicitly using pinMode.
1369  Using Arduino / Programming Questions / Re: Pressure Sensor and Arduino YUN on: October 16, 2013, 02:57:34 am
The analogue port converts voltages between 0 and 5 to a value between 0 and 1023.  So, an input of 498 is 5 * (498/1023)  which is about 2.43 volts
1370  Using Arduino / Programming Questions / Re: Reading arduino by a program written in C/C++! on: October 15, 2013, 04:30:37 pm
This is the Arduino forum. 
Do you need help on sending the byte, in which case this forum would be appropriate, or reading the byte (what device are you reading it with ?), in which case this forum might not be appropriate.
1371  Using Arduino / Programming Questions / Re: using analog sensors to work as digital? &more on: October 15, 2013, 08:16:59 am
Code:
if( currentSwitchState1 == 100 || currentSwitchState2 == 100 || currentSwitchState3 ==100 )
Have you any reason to suppose that any of the SwitchState variables have a value of exactly 100 when a switch is pressed ?  I suggest that you print them before testing them so that you can see the actual values.

Incidentally, the code above is in code tags which is what you have been asked to do but have not done.
1372  Using Arduino / Programming Questions / Re: How to prompt for a button press on: October 14, 2013, 03:07:36 pm
Quote
But how do you get it to run either function1() or function2() in an endless loop?  I don't want them to return
Mike has shown you a way to do this but you don't need to. 

Look at my pseudo code.  If state equals 1 or 2 then the code for either case will be run each time through loop() which will achieve the effect that you want.  Moreover,  should you ever need to introduce another button to exit either mode then it is easy to test for it in the switch/case.  If the new button press changed the case to 0, for example, you could return to prompting the user to select a mode, or the new button could switch between modes.
1373  Using Arduino / Programming Questions / Re: How to prompt for a button press on: October 14, 2013, 01:57:47 pm
Have a look at the use of the switch/case.

Some pseudo code to illustrate the principle
Code:
set state to 0
Show prompt on the screen

start of loop
  switch using state
    case 0
      if the mode 1 button is pressed
        set state to 1
      else if mode 2 button is pressed
        set state to 2
      end of if
     end of case 0
    
     case 1
        //code for mode 1 actions goes here
     end of case 1
    
     case 2
        //code for mode 2 actions goes here
     end of case 2
    
  end of switch  
end of loop
1374  Using Arduino / Programming Questions / Re: Writing a Function on: October 14, 2013, 03:11:24 am
Please accept my apologies for being helpful and answering your direct question in reply #1, but I am still intrigued as to why you want to waste time.
1375  Using Arduino / Programming Questions / Re: Writing a Function on: October 14, 2013, 02:40:12 am
Quote
Waste some time
Why waste it when you could use it ?  What does wasting time achieve , and how much time do you think that you are actually wasting ?
1376  Using Arduino / Programming Questions / Re: Writing a Function on: October 14, 2013, 01:06:43 am
Have a look at the bitwise operators, in particular the bitwise or operator

Quote
Bitwise OR (|)

The bitwise OR operator in C++ is the vertical bar symbol, |. Like the & operator, | operates independently each bit in its two surrounding integer expressions, but what it does is different (of course). The bitwise OR of two bits is 1 if either or both of the input bits is 1, otherwise it is 0. In other words:

    0  0  1  1    operand1
    0  1  0  1    operand2
    ----------
    0  1  1  1    (operand1 | operand2) - returned result
Here is an example of the bitwise OR used in a snippet of C++ code:

    int a =  92;    // in binary: 0000000001011100
    int b = 101;    // in binary: 0000000001100101
    int c = a | b;  // result:    0000000001111101, or 125 in decimal.
1377  Using Arduino / Programming Questions / Re: Need help with Strings. on: October 13, 2013, 07:42:39 am
Read http://forum.arduino.cc//index.php?topic=97455.0 then post some working code that shows the problem.
1378  Using Arduino / Programming Questions / Re: Errors converting from C (mostly "expected unqualified-id before...") on: October 12, 2013, 01:24:41 am
The Auto Format tool in the IDE reports that there are too many right curly braces in your code.  Until that is fixed it will not compile.
1379  Using Arduino / Programming Questions / Re: Fading LEDs in and out on a sequence on: October 11, 2013, 10:25:45 am
The description of what you want describes four states which would lend itself to implementation as a finite state machine.  Here is some code that may or may not work.  I cannot test it as present and there may well be things wrong with it.  It does, however, compile, which is a start.  If it does not work and you cannot work out what is wrong then post here and you will get some more help.

Code:
const byte myTriangle = 5;
const byte mySquare = 6;
byte brightness = 0;
const byte fadeAmount = 5;
const byte fadeDelay = 30;
byte state = 0;
const byte maxBrightness = 255;

void setup()
{
  pinMode(myTriangle, OUTPUT);
  pinMode(mySquare, OUTPUT);
  analogWrite(myTriangle, 0);
  analogWrite(mySquare, 0);
}

void loop()
{
  switch (state)
  {
  case 0:    //ramp up the triangle lamp
    analogWrite(myTriangle, brightness);
    delay(fadeDelay);
    brightness = brightness + fadeAmount;
    if (brightness >= maxBrightness)
    {
      analogWrite(myTriangle, maxBrightness);
      state = 1;
      brightness = 0;
    }
    break;

  case 1:    //ramp up the square lamp
    analogWrite(mySquare, brightness);
    delay(fadeDelay);
    brightness = brightness + fadeAmount;
    if (brightness >= maxBrightness)
    {
      analogWrite(mySquare, maxBrightness);     
      state = 2;
      brightness = maxBrightness;
    }
    break;

  case 2:    //ramp down the square lamp
    analogWrite(mySquare, brightness);
    delay(fadeDelay);
    brightness = brightness - fadeAmount;
    if (brightness <= 0)
    {
      analogWrite(mySquare, 0);     
      state = 3;
      brightness = maxBrightness;
    }
    break;

  case 3:    //ramp down the triangle lamp
    analogWrite(myTriangle, brightness);
    delay(fadeDelay);
    brightness = brightness - fadeAmount;
    if (brightness <= 0)
    {
      analogWrite(myTriangle, 0);     
      state = 0;
      brightness = maxBrightness;
    }
    break;
  }
}
1380  Using Arduino / Programming Questions / Re: Fading LEDs in and out on a sequence on: October 11, 2013, 09:56:04 am
The error is caused by your use of the reserved words triangle and square.  Change them to myTriangle and mySquare and the code compiles.  Whether it does what you want is a different matter.
Pages: 1 ... 90 91 [92] 93 94 ... 231