Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 15
61  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 05:19:18 pm
No problems; all I ask in return are some nice pictures or even a video of the code and hardware in working order!

Good luck smiley

/me
62  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 03:49:46 pm
Have a look at how random() is used. http://arduino.cc/en/Reference/RandomSeed

You can use a 'seed' to make the numbers more random. There is also a discussion here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235421386
63  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 11:54:56 am
Ahh...I knew that I'd make a mistake somewhere.

That's what I get for cooking it up without thinking. Anyway thanks halley for that!

/me
64  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 11:36:24 am
I think this is the kind of thing you need:

Quote
char* colours[7] = {  // Seven colours, 0-6
  "255, 255, 255",  // white
  "255, 0, 255",  // purple
  "0, 0, 255",  // blue
  "255, 255, 0",  // green
  "0, 255, 0",  // yellow
  "255, 153, 0",  // orange
  "255, 0, 0"};  // red

int randomVal;

void setup(){
}

void loop(){
}

void chooseColour() {
  randomVal = random(0, 6);  // Choose a random value, 0-6
  switch(randomVal) {
  case 0:
    white();
  case 1:
    purple();
  case 2:
    blue();
  case 3:
    green();
  case 4:
    yellow();
  case 5:
    orange();
  case 6:
    red();
  }
}

void white(){
}
void purple(){
}
void blue(){
}
void green(){
}
void yellow(){
}
void red(){
}
void orange(){
}

Edit -

Quote
byte colours[7][3] = {  // Seven colours, 0-6
  255, 255, 255,  // white
  255, 0, 255,  // purple
  0, 0, 255,  // blue
  255, 255, 0,  // green
  0, 255, 0,  // yellow
  255, 153, 0,  // orange
  255, 0, 0};  // red

int randomVal;

void setup(){
}

void loop(){
}

void chooseColour() {
  int randomVal = random(0, 6);  // Choose a random value, 0-6
  byte redComponent = colours[randomVal][0];
  byte greenComponent = colours[randomVal][1];
  byte blueComponent = colours[randomVal][2];
  analogWrite(redPin, redComponent);
  analogWrite(greenPin, greenComponent);
  analogWrite(bluePin, blueComponent);
}

It has an array of the Colour values. It then chooses a random value using the random() function. Then it uses a switch:case function to choose which colour function to go to with the selected case.

I think the reason you had difficulty with the #define statements was because you tried to use them the wrong way round. They just let the compiler replace the words e.g WHITE that you use in the code with the value attached to that statement.

Try adding this to your code (with all the additional stuff of course) and it should do what what you want.

The edited code courtesy of halley!

PS. This has been a learning curve for me too.

/me
65  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 06, 2009, 09:49:10 am
Nice one! Sorry I was being slow with my code, but a few things to add/change.

You could check for the button press by:

Code:
if(digitalRead(inPin) == HIGH){ // You said LOW instead
    code...
}

else {
    analogWrite(rpin, 0);
    analogWrite(gpin, 0);
    analogWrite(bpin, 0);
}

Which condenses it a bit and Is easier than checking twice.

You could write a function for each colour to colour fade and use;
randomVal = random(7);

to select which fade function to use.

/me
66  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 04, 2009, 06:46:50 pm
OK, it's 12:45 in England and I'm too tired to work out the fading code.

But I'll get back to it tomorrow!

/me
67  Forum 2005-2010 (read only) / Syntax & Programs / Re: help with specific rgb color, fade and random pick on: April 04, 2009, 06:32:42 pm
Do you have any underlying code or hardware to share?

I will draw up some code samples smiley-wink

/me
68  Forum 2005-2010 (read only) / Syntax & Programs / Re: multiple positions in an array on: April 06, 2009, 07:45:37 pm
I don't think this is possible as it involves more than one int calling the array at once and causing digitalRead() or any functions to process more than one thing at once which is not possible/they cannot do.

Sorry :p

/me
69  Forum 2005-2010 (read only) / Syntax & Programs / Re: multiple positions in an array on: April 06, 2009, 07:23:52 pm
Is there a problem with just calling them seperatly, one after the other? What context are you working in?

/me
70  Forum 2005-2010 (read only) / Syntax & Programs / Re: Multiple Servos on: March 29, 2009, 04:42:24 pm
Also, you could use a chip such as the TLC5940; a PWM I/O expander that will allow you to control up to 16 servos on each chip with great accuracy. You can also daisy-chain them so it is theoretically possible to have infinite servos. But obviously this is not actually possible! There is a also a great library for this chip.
71  Forum 2005-2010 (read only) / Syntax & Programs / Re: Developing A-Level Project: Memory on: March 31, 2009, 12:10:59 pm
Yes I do.

I've written a function that runs after each button press:

Code:
void writeTime(){
  EEPROM.write(memoryAddress, byte(timeSec));  // Save time in S
  memoryAddress++;  // Select next memory space (address)
}

memoryAddress is a variable starting at 0

Is this correct?

Also, is there an easy way to find the average of all the values?
72  Forum 2005-2010 (read only) / Syntax & Programs / Developing A-Level Project: Memory on: March 31, 2009, 11:14:13 am
I am developing the program for my Joystick project further. The Idea is that it times how long the user takes to press a certain button. And I would like to store these values.

Is the internal EEPROM the best place to store these?

Ben
73  Forum 2005-2010 (read only) / Syntax & Programs / Re: LCD Menu A-Level Project on: December 17, 2008, 03:06:37 pm
To time the length between a point and an input, would i:

* Set a variable with millis() say StartTime
* Start the display/time function
* Then to get time taken do: millis() - StartTime?
74  Forum 2005-2010 (read only) / Syntax & Programs / Re: LCD Menu A-Level Project on: December 17, 2008, 01:32:02 pm
Cheers, i'll have a go at displaying some messages. Then i'll try and get events to link to diffrent messages; and develop on for there.

 smiley
75  Forum 2005-2010 (read only) / Syntax & Programs / LCD Menu A-Level Project on: December 17, 2008, 12:43:56 pm
I am planning to make a LCD based project. It will use many different buttons as inputs.

The aim is to get the LCD to display a button name, then time from the message being displayed and the user pressing the button.

I have some ideas, but don't know the best way to go about:

* Storing/calling 1-2 line, 16 character messages
* Testing for inputs, sometimes more than one at a time

Any help please? Cheers,

Ben
Pages: 1 ... 3 4 [5] 6 7 ... 15