potentiometer to control color of matrix animation

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:

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!

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.

it’s not quite working out

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

Hi

try this

//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

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!

I would like to try to have it change colours after each frame.

Simply put the :-

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

Before each call to box

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);