Go Down

Topic: potentiometer to control color of matrix animation (Read 632 times) previous topic - next topic

whiskey

Dec 11, 2009, 06:24 pm Last Edit: Dec 11, 2009, 06:38 pm by whiskey Reason: 1
hi,

I have a basic box animation that runs fine but every time I want to change the colours I need to manually do it in the sketch and re-upload it, so I'm trying to hook up a potentiometer to control number value but it's not quite working out  that way.

any ideas? go easy on me I'm new!!

here's my code:


Code: [Select]
void loop(void) {
boxes(5,1,85);        //the 5 value changes the colour, not sure what to do with it?//
}

//boxes//
void boxes(int hue, byte times, int pause) {            
int value;
value = analogRead(__potentiometer);
value /= 4;
analogWrite (hue, value);     //this is the part I added//
  delay(pause);
  box1(hue);
  delay(pause);
  box2(hue);
  delay(pause);
  box3(hue);
  delay(pause);
  box4(hue);
}

//boxes//
void box1(int hue) {                              /* box animation */
 set_row_byte_hue(0,B00000000,hue);
 set_row_byte_hue(1,B00000000,hue);
 set_row_byte_hue(2,B00000000,hue);
 set_row_byte_hue(3,B00011000,hue);
 set_row_byte_hue(4,B00011000,hue);
 set_row_byte_hue(5,B00000000,hue);
 set_row_byte_hue(6,B00000000,hue);
 set_row_byte_hue(7,B00000000,hue);
}

void box2(int hue) {                              /* second box frame */
 set_row_byte_hue(0,B00000000,hue);
 set_row_byte_hue(1,B00000000,hue);
 set_row_byte_hue(2,B00111100,hue);
 set_row_byte_hue(3,B00100100,hue);
 set_row_byte_hue(4,B00100100,hue);
 set_row_byte_hue(5,B00111100,hue);
 set_row_byte_hue(6,B00000000,hue);
 set_row_byte_hue(7,B00000000,hue);
}
void box3(int hue) {                              /* more boxes!! */
 set_row_byte_hue(0,B00000000,hue);
 set_row_byte_hue(1,B01111110,hue);
 set_row_byte_hue(2,B01000010,hue);
 set_row_byte_hue(3,B01011010,hue);
 set_row_byte_hue(4,B01011010,hue);
 set_row_byte_hue(5,B01000010,hue);
 set_row_byte_hue(6,B01111110,hue);
 set_row_byte_hue(7,B00000000,hue);
}
void box4(int hue) {                              /* center box */
 set_row_byte_hue(0,B11111111,hue);
 set_row_byte_hue(1,B10000001,hue);
 set_row_byte_hue(2,B10111101,hue);
 set_row_byte_hue(3,B10100101,hue);
 set_row_byte_hue(4,B10100101,hue);
 set_row_byte_hue(5,B10111101,hue);
 set_row_byte_hue(6,B10000001,hue);
 set_row_byte_hue(7,B11111111,hue);
}



thanks!

PaulS

Where does __potentiometer get a value? Does it's value match the pin connected to the center connection on the potentiometer? Where are the other two pins connected?

You are reading the value of an analog pin, presumably. Then, you are writing to a PWM pin. What is connected to that pin?

You've omitted a bunch of code. What does set_row_byte_hue do?

But, the biggest thing you've omitted is a description of the problem.
Quote
it's not quite working out


What exactly is, or is not, happening? What do you want tp happen?

mike_pa

Hi

try this

Code: [Select]

//boxes//
void boxes(int hue, byte times, int pause) {
hue = analogRead(__potentiometer)/4; // hue 0...255
// analogWrite (hue, value);     //this is the part I added//
  delay(pause);
  box1(hue);
  delay(pause);
  box2(hue);
  delay(pause);
  box3(hue);
  delay(pause);
  box4(hue);
}


Mike

whiskey

#3
Dec 12, 2009, 02:33 pm Last Edit: Dec 12, 2009, 02:37 pm by whiskey Reason: 1
well looking back at the original post I guess I wasn't too clear as to what I was asking, I'll try better next time!

thanks mike, not sure why I was writing the "value" It was mainly just a copy n paste with a little hope that it would work but I guess in this case value and hue are the same.

so now that I can control of the colour, it's still only able to change it's colour after it completes the full animation(4 frames). I would like to try to have it change colours after each frame. It's a start though!

Grumpy_Mike

#4
Dec 14, 2009, 10:03 am Last Edit: Dec 14, 2009, 10:04 am by Grumpy_Mike Reason: 1
Quote
I would like to try to have it change colours after each frame.


Simply put the :-
Code: [Select]

hue = analogRead(__potentiometer)/4; // hue 0...255

Before each call to box
Code: [Select]

delay(pause);
hue = analogRead(__potentiometer)/4; // hue 0...255
  box1(hue);
  delay(pause);
hue = analogRead(__potentiometer)/4; // hue 0...255
  box2(hue);
  delay(pause);
hue = analogRead(__potentiometer)/4; // hue 0...255
  box3(hue);
  delay(pause);
hue = analogRead(__potentiometer)/4; // hue 0...255
  box4(hue);

Go Up