Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 251
61  Using Arduino / Project Guidance / Re: How to increase a rf receivers pin voltage on: September 08, 2014, 03:36:28 pm
What RF receiver are you using, what pin are you referring to and are you trying to directly trigger the US from the receiver?
62  Using Arduino / Programming Questions / Re: Mysterious "ghost definition" of a user-defined function on: September 08, 2014, 02:12:44 pm
Plus,
Quote
Serial.write(output);
Is not the same as Output, hopefully just a typo.

And the compiler doesn't know what "CloseDome;" is.

Also, I wasn't aware this worked:
Quote
if (IsDead && DomeOpen) // Somehow IsDead works even though it is not written as IsDead()
  {
    DomeClosed = CloseDome; // Close the dome. Should put a check in this function to verify success.
    DomeOpen = false; // This should only be set to false if the closeDome procedure was successful.
  }
63  Using Arduino / Programming Questions / Re: MIDI song display on: September 08, 2014, 01:21:58 pm
Just use basic math.

Quote
switch (cc) {
        case 101:
          lcd.setCursor(0,0);
          lcd.print("SONG 1");//THE NAME HAVE TO BE 16 CHARACTER
          break;
        case 102:
          lcd.setCursor(0,0);
          lcd.print("      SONG 2    ");
          break;
        case 103:
          lcd.setCursor(0,0);
          lcd.print("      SONG 3     ");
          break;
        case 104:
          lcd.setCursor(0,0);
          lcd.print("      SONG 4     ");
          break;
        case 105:
          lcd.setCursor(0,0);
          lcd.print("      SONG 5     ");
          break;
        case 106:
          lcd.setCursor(0,0);
          lcd.print("      SONG 6     ");
          break;
        case 107:
          lcd.setCursor(0,0);
          lcd.print("      SONG 7     ");
          break;
        case 108:
          lcd.setCursor(0,0);
          lcd.print("      SONG 8     ");
          break;
        case 109:
          lcd.setCursor(0,0);
          lcd.print("      SONG 9     ");
          break;
        case 110:
          lcd.setCursor(0,0);
          lcd.print("      SONG 10     ");
          break;
        case 111:
          lcd.setCursor(0,0);
          lcd.print("     SONG 11   ");
          break;
        case 112:
          lcd.setCursor(0,0);
          lcd.print("      SONG 12     ");
          break;
        case 113:
          lcd.setCursor(0,0);
          lcd.print("    SONG 13      ");
          break;
        case 114:
          lcd.setCursor(0,0);
          lcd.print("      SONG 14     ");
          break; 
        }
All of this can be changed to:
LCD.print("Song ");
LCD.print(cc - 100); // be careful here, is cc a single byte, or individual chars('1', '0', '0') that need to be converted to a single number?

Same with this but you are just converting the number to the corresponding letter.
Quote
if (message ==1){//is it a message noteON?     
        note = Serial.read();// read Control change value
        switch (note) {
        case 11:
          lcd.setCursor(0,1);
          lcd.print("    A    ");
          break;
        case 12:
          lcd.setCursor(0,1);
          lcd.print("    B    ");
          break;
        case 13:
          lcd.setCursor(0,1);
          lcd.print("    C    ");
          break;
        }
      }
LCD.print(note + 54); // 'A' = 65(dec) -> 'A' - 11(note) = 54
64  Development / Other Software Development / Re: Some new core functions on: September 08, 2014, 11:54:38 am
The changes are made and I added median and mode. However, I can't do any tests on my end. If someone wants to try the new library functions and post the results, that would be great.

Code:
int myArray[] = {
  25, 1000, 420, 1000, 10, 345, 862};

void setup(){
  Serial.begin(115200);
  Serial.println(mean(myArray));
  Serial.println(median(myArray));
  Serial.println(mode(myArray));
}

void loop() {

}

Note: I didn't change anything in the .cpp file, so I did not attach it.

In regards to the mode function, I need to figure out a way to see if I can change the return result if there is more than one outcome i.e. Bimodal.

Bimodal: A set of data is bimodal if it has 2 modes (i.e., two numbers that occur most often, and the same number of times).

Edit: Error in the mean() function, tmp was not set to zero, so the result was incorrect. Fixed.

Code:
int myArray[] = {
  25, 1000, 25, 1000, 1000, 345, 862};

void setup(){
  Serial.begin(115200);

  Serial.println(mean(myArray));
  Serial.println(median(myArray));
  Serial.println(mode(myArray));
}

void loop() {

}

Result:
Quote
608 // mean
862 // median
1000 // mode
65  Development / Other Software Development / Re: Some new core functions on: September 08, 2014, 08:29:40 am
If we do implement the 'average' function, can we please, please, please not call it 'average'?

It was Excel that started the rot, unfortunately.  There isn't a mathematical definition for average.  Rather, there are three types of average: mean, median and  mode.  

Therefore, if this suggestion is adopted I suggest the function is called 'mean()'.

Ok I will change it to mean(), and I'll make median and mode too.

@Pyro
I never did look into C++11, :/ Looks like I got homework.
66  Development / Other Software Development / Re: Some new core functions on: September 07, 2014, 12:30:11 pm
Quote
Your template is compiled inline.
Thats it? So why aren't all if not most of the functions inline?

I have a lot of functions to change then.
67  Using Arduino / Programming Questions / Re: A Loop is making my brain hurt on: September 06, 2014, 11:47:24 pm
Based on what you wrote, I can assume this is what you were going for, but I like Bulldogs's method better.

for(byte i = 0; i < 50; i++)
{
   setRegisterPin(i, HIGH); //RED
   if( (i % 4) == 3) i+=4;
}

Code:

void setup()
{
  Serial.begin(115200);

  Serial.print("Red: ");
  for(byte i = 0; i < 50; i++) // red starts at 0
  {
    Serial.print(i);
    Serial.print(", ");
    //setRegisterPin(i, HIGH); //RED
    if( (i % 4) == 3) i+=4;
  }
  Serial.println();
 
  Serial.print("Blue: ");
  for(byte i = 4; i < 50; i++)// blue starts at 4
  {
    Serial.print(i);
    Serial.print(", ");
    //setRegisterPin(i-1, HIGH); //BLUE
    if( (i % 4) == 3) i+=4;
  }
}

void loop() {

}

Result:
Quote
Red: 0, 1, 2, 3, 8, 9, 10, 11, 16, 17, 18, 19, 24, 25, 26, 27, 32, 33, 34, 35, 40, 41, 42, 43, 48, 49,
Blue: 4, 5, 6, 7, 12, 13, 14, 15, 20, 21, 22, 23, 28, 29, 30, 31, 36, 37, 38, 39, 44, 45, 46, 47,
68  Using Arduino / Programming Questions / Re: Help from someone more advanced than myself on: September 06, 2014, 10:01:53 pm
Quote
#define REQ ( R1 * R2 ) / ( R1 +R2 )                     // The equation that calculates REQ

This method is fine for two resistors in parallel but it gets rather tedious when you have multiple resistors. I prefer to use this method:  1 / ( (1/R1) + (1/R2) +...+ (1/Rn) )

The resistor values can be inside an array and a FOR loop can be used to add them up.
Edit: Not type long, must be float
Code:
float Total =0, Final;
for(byte i=0; i < Num_of_Resistors; i++)
   Total += (1 / float(Res[ i ]));

Final = (1 / Total);

Example 1:
Code:
int array[3] = {500,500,500};
void setup()
{
  Serial.begin(115200);
  Serial.println( Req(array, 3) );
}

void loop() {

}

int Req(int * Res, byte Num_of_Resistors)
{
  float Total = 0;
  for(byte i=0; i < Num_of_Resistors; i++)
    Total += (1 / float(Res[ i ]));

  return (1 / Total);
}

Example 2: (Such Fanciness, much wow)
Code:
//Note the location of this function, it is at the top of the code and not the bottom.
template<class T, size_t N>
T Req(T (&Res)[N])
{
  float Total = 0;
  for(byte i=0; i < N; i++)
    Total += (1 / float(Res[ i ]));

  return (1 / Total);
}

int array[3] = {500,500,500};
void setup()
{
  Serial.begin(115200);
  Serial.println( Req(array) );
}

void loop() {

}

69  Development / Other Software Development / Re: Some new core functions on: September 06, 2014, 06:29:51 pm
I put it in some obscure bit-twiddling library, just for now.

Besides, there is a one in a million chance they will ever see these functions, and a one in a billion chance these functions will be added.

We have been asking to have things added for years, and exactly how many of them were ever implemented?

If these functions help anyone, even just one person, I will be happy.
70  Using Arduino / Programming Questions / Re: Help from someone more advanced than myself on: September 06, 2014, 06:19:16 pm
All you need to do is use Serial.parseInt() for both values. nothing more.

In serial monitor type 1239 4567 there is a space between them
Code:
int R1, R2;
void setup()
{
  Serial.begin(115200);
}

void loop() {
  if(Serial.available() > 0)
  {
    R1 = Serial.parseInt();
    R2 = Serial.parseInt();
    Serial.print(R1);
    Serial.print('\t');
    Serial.println(R2);
  }
}

You can add in the other things once you understand what the code is doing.

For multiple values with prompts, I would use a counter to keep track of the values entered and an array to store the values in.
71  Using Arduino / Project Guidance / Re: 25 keys midi piano on: September 06, 2014, 06:01:53 pm
You don't need to buy a Mega, you just need to go to the link I gave you or search for 4 74HC165N 8 Bit Parallel-In shift registers. They are very cheap
72  Using Arduino / Project Guidance / Re: 25 keys midi piano on: September 06, 2014, 05:53:11 pm
You can use 4 of these 74HC165N 8 Bit Parallel-In shift registers.

This here is a 10 piece lot. Link
73  Using Arduino / Programming Questions / Re: Unable to use an array on arduino pro mini on: September 06, 2014, 02:29:23 pm
Why are they ints if the values don't go over 255?
And why make the arrays as r_colValues[1024] if you only have about 60 elements in each array?
74  Development / Other Software Development / Re: Some new core functions on: September 06, 2014, 12:25:00 pm
Library!

Added these files to your normal libraries folder under the sketch folder, and add #include <Core_Ext.h> like so.

Quote
#ifndef Arduino_h
#define Arduino_h

#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <avr/pgmspace.h>
#include <avr/io.h>
#include <avr/interrupt.h>

#include "binary.h"
#include <Core_Ext.h>

Save the file, and there you go.
75  Using Arduino / Programming Questions / Re: Virtual Wire Library questions on: September 06, 2014, 12:08:41 pm
Quote
#include <VirtualWire.h>
#include <Servo.h>

These two don't work well with each other. Try the library in this thread look for the newest version.

Added: Direct link ServoTimer2
Pages: 1 ... 3 4 [5] 6 7 ... 251