Pages: [1]   Go Down
Author Topic: potentiometer to control color of matrix animation  (Read 613 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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!
« Last Edit: December 11, 2009, 12:38:33 pm by whiskey » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50512
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 149
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

try this

Code:
//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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 81
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
« Last Edit: December 12, 2009, 08:37:48 am by whiskey » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 637
Posts: 34602
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Simply put the :-
Code:
hue = analogRead(__potentiometer)/4; // hue 0...255
Before each call to box
Code:
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);
« Last Edit: December 14, 2009, 04:04:12 am by Grumpy_Mike » Logged

Pages: [1]   Go Up
Jump to: