Skip to content

Commit

Permalink
Add Documentation
Browse files Browse the repository at this point in the history
Added a lot of comments and added io2 and io3 to the setup.
  • Loading branch information
themusicdan authored Sep 5, 2016
1 parent fdc7e18 commit 838654b
Showing 1 changed file with 55 additions and 18 deletions.
73 changes: 55 additions & 18 deletions arduino/cpanel.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Include FastLED library
#include <FastLED.h>

// Define pins and constants for ease of use.
#define NUM_PWR_IO 3
#define NUM_LEDS 34
#define LED_PIN 11
Expand All @@ -10,43 +12,62 @@
#define PULSE_CYCLE 4000
#define RUN_DELAY 50

// Create parameters for editing later.
int handle_rgb_light(struct pwr_io_ctrl ctrls[NUM_PWR_IO]);
int handle_light_adjustment(struct pwr_io_ctrl ctrls[NUM_PWR_IO]);
int update_value(struct pwr_io_ctrl *ctrl_obj);
int set_led_color(int color1, int color2, int color3);

// Create structs
// pwr_io_ctrl is used for storing all of the values pertaining to a specific input/output.
struct pwr_io_ctrl{
int out_pin;
int analog_in_pin;
int current_value;
unsigned long last_touched;
int base_color[3];
int out_pin; // Digital output pin
int analog_in_pin; // Analog input pin
int current_value; // Current brightness value
unsigned long last_touched; // Whether this was the last button touched
int base_color[3];
/** 3 value array describing RGB color (0-255). This base_color value is used whenever the
* brightness is being adjusted. For example, if the user turns first knob, the lights
* inside the control box will turn cyan and a number of lights will turn on. The number
* of lights are used to indicate the brightness setting of the first output.
*/
};

// Pulse is used for pulsing a color regularly over a base color
struct pulse {
int calls_per_cycle;
float current_color[3];
int pulse_color[3];
int retracting;
int calls_per_cycle; // The number of times that the pulse will need to be called.
float current_color[3]; // 3 value array describing current RGB color (0-255)
int pulse_color[3]; // 3 value array describing RGB color to pulse (0-255)
int retracting; // Whether the pulsed color is being activated or deactivated
};

//Initialize Input pin & Output Pin pairs
struct pwr_io_ctrl io1 = {3, 1, 0, 0, {0, 255, 255}};
struct pwr_io_ctrl io2 = {9, 6, 0, 0, {255, 255, 0}};
struct pwr_io_ctrl io1 = {3, 1, 0, 0, {0, 255, 255}};
// Output 3 is controlled with analog 1, and starts with value 0, never touched, with base color cyan
struct pwr_io_ctrl io2 = {9, 6, 0, 0, {255, 255, 0}};
// Output 6 is controlled with analog 9, and starts with value 0, never touched, with base color yellow
struct pwr_io_ctrl io3 = {5, 4, 0, 0, {120, 0, 255}};
// Output 4 is controlled with analog 5, and starts with value 0, never touched, with base color purple
//struct pwr_io_ctrl io4 = {6, 2, 0, 0, {80, 255, 0}};

struct pwr_io_ctrl ctrls[NUM_PWR_IO] = {io1, io2, io3};
struct pwr_io_ctrl ctrls[NUM_PWR_IO] = {io1, io2, io3}; // Group the controls together

struct pulse passive_pulse = {PULSE_CYCLE / RUN_DELAY, {0.0, 0.0, 0.0}, {PASSIVE}, 0};
struct pulse passive_pulse = {PULSE_CYCLE / RUN_DELAY, {0.0, 0.0, 0.0}, {PASSIVE}, 0};
struct pulse active_pulse = {PULSE_CYCLE / RUN_DELAY, {0.0, 0.0, 0.0}, {ACTIVE}, 0};

//Define RGB LED array
CRGB leds[NUM_LEDS];

void setup() {
pinMode(io1.out_pin, OUTPUT);
pinMode(io1.analog_in_pin, INPUT);
//pinMode(io1.out_pin, OUTPUT);
//pinMode(io1.out_pin, OUTPUT);

pinMode(io2.out_pin, OUTPUT);
pinMode(io2.analog_in_pin, INPUT);

pinMode(io3.out_pin, OUTPUT);
pinMode(io3.analog_in_pin, INPUT);

FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
set_led_color(0, 255, 70);
Serial.begin(9600); // open the serial port at 9600 bps:
Expand All @@ -63,6 +84,19 @@ void loop() {
Serial.print(", val: ");
Serial.print(analogRead(io1.analog_in_pin));
Serial.println();

Serial.print("PIN: ");
Serial.print(io2.analog_in_pin);
Serial.print(", val: ");
Serial.print(analogRead(io2.analog_in_pin));
Serial.println();

Serial.print("PIN: ");
Serial.print(io3.analog_in_pin);
Serial.print(", val: ");
Serial.print(analogRead(io3.analog_in_pin));
Serial.println();

delay(RUN_DELAY);
}

Expand Down Expand Up @@ -123,6 +157,7 @@ int set_rgb_circle(struct pwr_io_ctrl *ctrl) {
}
FastLED.show();
}

/** Check if there are any potentiometers / lights
* whose value has been changed within the frames
* of the idle time. If it has, we can update RGB
Expand Down Expand Up @@ -157,34 +192,36 @@ int handle_rgb_light(struct pwr_io_ctrl ctrls[NUM_PWR_IO]) {
return 0;
}


int handle_light_adjustment(struct pwr_io_ctrl ctrls[NUM_PWR_IO]) {
int i;
for (i = 0; i < NUM_PWR_IO; i++)
update_value(&ctrls[i]);
return 0;
}


int update_value(struct pwr_io_ctrl *ctrl_obj) {
int val = map(analogRead(ctrl_obj->analog_in_pin), 0, 1023, 0, 255);

//Avoid fluctuation flickering on low & high by not changing unless major
if (ctrl_obj->current_value + FLUCT_THRESH > val
&& ctrl_obj->current_value - FLUCT_THRESH < val)
return 0;

if (val <= FLUCT_THRESH)
val = 0;
else if (val >= 255 - FLUCT_THRESH)
val = 255;



analogWrite(ctrl_obj->out_pin, val);

ctrl_obj->current_value = val;
ctrl_obj->last_touched = millis();
return 0;
}

// Basic method to set all the leds to the given color value.
int set_led_color(int color1, int color2, int color3) {
int i;
for (i = 0; i < NUM_LEDS; i++)
Expand Down

0 comments on commit 838654b

Please sign in to comment.