Show Posts
Pages: [1]
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: generate a series of random numbers on: October 12, 2009, 12:17:33 pm
I need for the script to return something like this:

3, 4, 6
-
5, 6
-
2, 4
-
1, 2, 3, 5
-
3
-
1, 2, 4, 5, 6

...and so on,


a random selection of the array in a random quantaty

hope this makes it clear
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: generate a series of random numbers on: October 12, 2009, 12:13:18 pm
i tried that... unfortunately whichMotors = random(0, 6); only returns 1 random number. Therefor it will only write on one servo at a time.

The array contains the 6 servos. By creating a variable - quantatyMotor = random(0, 6) - that defines the quantity of servos to be activated in the for loop each time it runs I was able to make it write to a random quantity of servos.

However it always starts on the first servo since the variable that tells the servos to move is always a single int.

What i really need is for the loop to say something like this:

each time it runs, select a random group of servos between 0 and 6 and write on them.
This group may be composed of just one random servo or all of them, or just the number 4 and 2.

I don't know if I'm explaining myself right...

thanks

3  Forum 2005-2010 (read only) / Syntax & Programs / Re: generate a series of random numbers on: October 12, 2009, 11:50:39 am
this seams to me as a different way of creating an array with for the servos. It doesn't help me with the writing on a random set of servos.

thanks any way
4  Forum 2005-2010 (read only) / Syntax & Programs / generate a series of random numbers on: October 12, 2009, 09:37:10 am
How can i generate a series of random number to select multiple positions of an array?

I need to set on which loop, a random number of servos moving and also on a random order.

So far I managed to do it like this but I can't seem to find a way to associate a random number with which of servos to move.

code
--------------------------------------------------------------------------

#include <Servo.h>

/////////////
Servo s2;  //     #######################
Servo s3;  //     #                     #
Servo s4;  //     #  (2)    (3)    (4)  #
Servo s5;  //     #                     #
Servo s6;  //     #  (5)    (6)    (7)  #
Servo s7;  //     #                   _ #
           //     #######################
/////////////
 
Servo exec[] = {s2, s3, s4, s5, s6, s7};

int whichMotors;
int quantatyMotor;


 
void setup(){

  Serial.begin(9600);
  
  s2.attach(2);
  s3.attach(3);
  s4.attach(4);
  s5.attach(5);
  s6.attach(6);
  s7.attach(7);
    
  randomSeed(analogRead(0));
}
 
void loop(){
  

  quantatyMotor = random(0, 6);
  
  
  
  
   for (int i=0; i <= quantatyMotor; i++){
    
      
      
      Serial.println("I");
      Serial.println(i+2);
      Serial.println("QUANTATY OF MOTORS");
      Serial.println(quantatyMotor+1);
      
      whichMotors = random(0, 6);
      
       exec.write(10);
       delay (100);
       exec.write(40);
      
      Serial.println("MOTOR");
      Serial.println(whichMotors);
    
      
   }
  
  
delay(4000);


}


---------------------------------------------------------------------------

What i need is to move for instance the 3rd and the 5th motor, afterward the 1st, the 2nd, and the 6th, and next the 1st, the 4th the 5th and the 6th.

Sometimes only one, and sometime all of them.
Any help greatly appreciated!

Cheers!
5  Forum 2005-2010 (read only) / Syntax & Programs / Array to object on: October 11, 2009, 11:26:39 pm
Hey there:

Can someone tell me how to use the array to control the servo object?

---------------------------------------------------------------------------
code:


#include <Servo.h>

Servo s2;
Servo s3;
Servo s4;  
Servo s5;
Servo s6;
Servo s7;

char* exec[] = {"s2", "s3", "s4", "s5", "s6", "s7"};
long randomNumber;
 
void setup(){

  Serial.begin(9600);
  
  s2.attach(2);
  s3.attach(3);
  s4.attach(4);
  s5.attach(5);
  s6.attach(6);
  s7.attach(7);
  
  
}
 
void loop(){
  
  randomNumber = random(0, 6);
  Serial.println(randomNumber);
  Serial.println(exec[randomNumber]);
  
  exec[randomNumber].write(10);
  delay (1500);
  exec[randomNumber].write(40);

}


---------------------------------------------------------------------------

It returns the following error:

In function 'void loop()':
error: request for member 'write' in 'exec[randomNumber]', which is of non-class type 'char*'



Cheers!
6  Forum 2005-2010 (read only) / Troubleshooting / avrdude: write to file '/../sketch.hex' failed on: April 14, 2009, 11:52:10 pm
I have recently downloaded the 0015 version of arduino software and one sketch that never gave me any problems in the 0012 version, doesn't upload to the board..

Some problem with the .HEX file...

these are the error messages:

----------------------------------------------------------------------

Code:
/tmp/build37204.tmp/core.a(wiring_serial.c.o): In function `__vector_18':

/Users/pedrogoncalves/Desktop/arduino-0015/hardware/cores/arduino/wiring_serial.c:112: multiple definition of `__vector_18'

/tmp/build37204.tmp/core.a(HardwareSerial.cpp.o):/Users/pedrogoncalves/Desktop/arduino-0015/hardware/cores/arduino/HardwareSerial.cpp:95: first defined here

Couldn't determine program size: hardware/tools/avr/bin/avr-size: '/tmp/build37204.tmp/arduino_flash.hex': No such file


any way of making it work again...


going back to the 0012 doesn't work for me because I'm working with a Duemilanove board and the java updates i did to run the 0015 version messed up the older versions.

Cheers
7  Forum 2005-2010 (read only) / Troubleshooting / voltage regulator replacement on: October 21, 2009, 05:15:25 pm
I think i have just messed up my arduino.. I've accidentally set the external power source to 12 v and crossed some wire (it was a bit messy and i dont remember exactly what i did) and i think the voltage regulator short circuited and a couple of minuts after it was still very hot..

Is it possible to replace it? Or is the problem probably somewhere else?

Every thing in the board seams to be working just fine except for the 5v and ground..

Cheers!
8  Forum 2005-2010 (read only) / Troubleshooting / voltage regulator replacement on: October 21, 2009, 05:14:17 pm
I think i have just messed up my arduino.. I've accidentally set the external power source to 12 v and crossed some wire (it was a bit messy and i dont remember exactly what i did) and i think the voltage regulator short circuited and a couple of minuts after it was still very hot..

Is it possible to replace it? Or is the problem probably somewhere else?

Every thing in the board seams to be working just fine except for the 5v and ground..

Cheers!
9  Forum 2005-2010 (read only) / Troubleshooting / multiple computers sharing a single arduino on: April 08, 2009, 11:22:34 am
is it possible to connect a single arduino to multiple computers?
need to send the information of only three sensors to three different computers... can i do it with only one arduino? or do i need three??

hacking the usb cable..?

cheers
10  Forum 2005-2010 (read only) / Troubleshooting / Re: LiquidCrystal does not work... on: March 09, 2009, 04:37:12 pm
thanks!!! that was it.....
11  Forum 2005-2010 (read only) / Troubleshooting / Re: LiquidCrystal does not work... on: March 07, 2009, 06:16:08 pm
yes I have. I have a normal potentiometer connected to the contrast pin of the lcd and when it is turned the contrast changes: the top line turns all the squares brighter and almost no changes occur in the bottom line.. but still no text..

I am using the following code:


#include <LiquidCrystal.h>

// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

void setup()
{
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{
}


and the XIAMEN OCULAR GDM1602K LCD
12  Forum 2005-2010 (read only) / Troubleshooting / LiquidCrystal does not work... on: March 07, 2009, 05:08:50 pm
Everything uploads and compiles... but nothing shows up in the lcd. All the connections seem to be ok but still no letters in the display.

any sugestions... what am i doing wrong???
13  Forum 2005-2010 (read only) / Interfacing / Modify velocity of a servo motor on: October 03, 2009, 09:52:19 pm
Is it possible to decrease the velocity of a servo motor?
cheers!
Pages: [1]