Show Posts
Pages: 1 ... 53 54 [55] 56 57 ... 196
811  Using Arduino / Programming Questions / Re: newbie needs some coding help for leds please on: November 19, 2013, 09:02:54 pm
If you don't want the random numbers to be duplicates, then use this sketch I made.
Code:
long randNumber;
int Count = 20
int list[Count];
int i=0;
boolean found = false;

void setup(){
  for(int j =0; j<Count;j++)
    list[j] = 0; // set all the array blocks to 0

  Serial.begin(9600);
  randomSeed(1);
  delay(50);

  while(i < Count) // will cycle through until the array is filled
   {
    randNumber = random(1, Count); // lowest value is 1, and highest value is 20
    for(int L=0;L < i;L++) // will cycle through the list array and check the new number too
    {
      found = false;
      if(list[L] == randNumber) // if the random number IS found, then its a duplicate and discard it
      {
        found = true; // number has a duplicate, no good
        break;
      }
    }

    if( !found )// if the random number does NOT have a duplicate, add it to the list array
    {
        list[i] = randNumber;
        Serial.println(list[i]);
        i++;
    }
  }
}

void loop()
{
  //empty
}

Output with no duplicates:
Quote
12
8
9
18
10
14
4
19
17
11
13
1
7
6
3
2
16
15
5
812  Using Arduino / Programming Questions / Re: newbie needs some coding help for leds please on: November 19, 2013, 08:19:10 pm
Not sure if it does output duplicate number or not, but why not just do a test to see if you get duplicate numbers from that example sketch?

Also, you are correct, that quote is from the movie HACKERS, and that's where I got it from. And if I ever meet Mathew Lillard, I want to say "HACK THE PLANET!" and see what his reaction is.  smiley-lol
813  Using Arduino / Programming Questions / Re: newbie needs some coding help for leds please on: November 19, 2013, 07:56:08 pm
Serial.begin(9600) allows you to use the serial monitor. It is essential for debugging code. Serial.begin initializes the use of the serial monitor at 9600 baud or rate at which the data is transferred.

With your arduino plugged into your computer, you can press Ctrl + Shift + M, or in the top right corner of the arduino IDE, there is a box with a little magnifying glass.  Or, simply go to the Tool menu and click Serial Monitor.
814  Using Arduino / Programming Questions / Re: newbie needs some coding help for leds please on: November 19, 2013, 07:35:43 pm
Quote
my question is how do i make them randomly shuffle on and stay on? i would like the shuffle to be the same all the time.
Ok thats easy, there is are functions called random() and randomSeed(). Set a value for randomSeed and it initilizes the random function to give random outcomes, but the same random outcomes every time. (Its random but not random, if that makes any sense)

See Here
815  Using Arduino / Project Guidance / Re: Reading hole punch in paper on: November 19, 2013, 07:12:00 pm
Why not just use a strip of LEDs and photoresistors? If there is a hole, the corresponding PR will turn on and emit a signal to the Arduino.

If your using foil, then you can use probes to touch the foil. If a probe goes over a hole, it can be then pulled HIGH with a pull up resistor.
816  Using Arduino / Project Guidance / Re: Android Controlled LEDs via Bluetooth on: November 18, 2013, 07:25:31 pm
An Arduino UNO, and a JY-MCU bluetooth module will work fine.
817  Using Arduino / Project Guidance / Re: Problem with PushButton on: November 18, 2013, 05:39:52 pm
How are you using pins 4 and 5 as buttons if they are connected to your lcd? Unless your using the Analog pins A4 and A5.

What model lcd are you using, can you provide a link or picture?
818  Using Arduino / Programming Questions / Re: Servo/channel reverse code for RC transmitter? on: November 18, 2013, 04:15:17 pm
Maybe this will help you understand a little better.

By setting the mode of an analog pin to OUTPUT, your not setting it as an analog output, but as a digital output. An analog pin can input a voltage and assign it to a range from 0 - 1023. However it can not output the same range. Once the analog pin is set as an OUTPUT, it becomes a digital pin that outputs a (1 or 0).  In order to output an analog signal, it would require a DAC.

So you would send a bunch bytes (actually nibbles) and based on what you send will determine if the output is a negative voltage or positive voltage. See HERE

Added:
For your servo problem. A servo expects a pulse every 20ms, and depending on the time the pulse is high, will determine the direction it rotates.
1ms = 0 deg.
1.5ms = 90 deg.
2ms = 180 deg.

Continuous servos of course change direction and speed based on the high pulse time.  See HERE

You need to factor in the total time (20ms) minus the high time (1ms - 2ms).

Simple example:
Code:
void setup()
{
  //Set pin modes
}
void loop()
{
  direction(1.0); // 0 deg
  delay(1000);
  direction(1.5); // 90 deg
  delay(1000);
  direction(2.0); // 180 deg
  delay(1000);
}

void direction(double HT)
{
  digitalWrite(9, HIGH);
  //some_timer(HT * 1000); // 1ms High
  digitalWrite(9,LOW);
  //some_timer(20000 - (HT * 1000)); // 19ms Low
}
819  Using Arduino / Programming Questions / Re: Code Problem on: November 17, 2013, 06:31:46 pm
Make a copy of the current value and store it as "old value", then do something with the two values, either compare them, take the difference or whatever and finally update the old value.
820  Using Arduino / Programming Questions / Re: Code Problem on: November 17, 2013, 06:05:18 pm
Well read_compass is returning a value, so try this.
Code:
void rotate_robot_right(){
  while(read_compass() < 90){
    //right
    digitalWrite(cA, HIGH); //Establishes direction of Channel A
    digitalWrite(cB, HIGH);  //Establishes backward direction of Channel B
    analogWrite(3, 245);  //Spins the motor on Channel A at max speed
    analogWrite(11, 255); //Spins the motor on Channel B at max speed

    //read_compass();
  }
}
821  Using Arduino / Programming Questions / Re: Code Problem on: November 17, 2013, 05:51:56 pm
Why are you re-initializing headingValue again in  your read_compass function? Have you tried to debug your code with the serial monitor to see what the value of headingValue is?
822  Using Arduino / Programming Questions / Re: New B in desperate need of guidence on: November 16, 2013, 12:09:05 am
You have EEPROM.Read( address ) in your code, yet your not doing anything with it. You could use a FOR loop in the setup() function to set the led array. Or you can store the last counter value and set the leds that way.
823  Using Arduino / Displays / Re: Need some help with TFT display. on: November 13, 2013, 11:37:58 am
First, you need to have the adapter shield too. Second you need to download the UTFT and UTFTTouch libraries. They come with example sketches.
824  Using Arduino / Programming Questions / Re: Receiving multidimensional array in a function on: November 09, 2013, 04:24:52 pm
You would need to change "findCommand(char cmd[]){" to look for a pointer "findCommand(char * cmd){"
Then you will also need to use the strcmp() function.

Not a great example but it should help get you going.
Code:
char command[][9] = {
  "RAPID","SHORT","SOLID","OFF"};

void setup()
{
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  for(int i = 0; i < 4; i++)
  {
    getCommand(command[i]);
    Serial.println(command[i]);
    delay(2000);
  }
}

void loop() {

}


void getCommand(char * cmd)
{
  if(!strcmp(cmd,"RAPID"))
  {
    digitalWrite(13,HIGH);
    delay(100);
    digitalWrite(13,LOW);
  }

  if(!strcmp(cmd,"SHORT"))
  {
    digitalWrite(13,HIGH);   
    delay(1000);
    digitalWrite(13,LOW);
  }   

  if(!strcmp(cmd,"SOLID"))
  {
    digitalWrite(13,HIGH);
  }

  if(!strcmp(cmd,"OFF"))
  {
    digitalWrite(13,LOW);
  }

}

Added:
If you want to use Case Statements, then you need to assign or #define the "command" to a number.
So RAPID = 0, SHORT = 1, SOLID = 2, OFF = 3 and so on.
825  Development / Other Software Development / Re: New Password Library on: November 08, 2013, 04:45:13 pm
UPDATE: (Actually finished it almost two weeks ago)
My password library is technically done, but now I'm deciding whether or not I should allow the user to choose how the data is stored. Right now both the passwords and usernames are stored in the heap, rather than the stack. However, I am thinking maybe I should allow the user to have a choice of where they store their data. The heap seems to take up more compile memory, but it also seems more efficient, and less likely to cause memory problems. Whereas the if the data was stored in the stack via 2D arrays, then it would take up less memory, but may cause problems later.

So if anyone thinks its a good idea to implement, let me know, if not then I'll keep the library as is.

Oh, I decided to not implement the LCD or Keypad libraries in my library, mainly because not everyone uses the standard LCD and Keypad libraries. But it will still work with them regardless of the library(s) used.
Pages: 1 ... 53 54 [55] 56 57 ... 196