#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
const int player_counter = 0;
const int player_limit=6;
const int player_array_size=player_limit-1;
const int number_of_leds = 20;
const int number_of_PWMS = 4;
int player[player_array_size][number_of_leds];
int myleds_PWM_unit[number_of_leds];
int myleds_port_number[number_of_leds];
int global_delay=200;
// Define PCA9685 addresses
#define PCA9685_ADDRESS_0 0x40
#define PCA9685_ADDRESS_1 0x41
#define PCA9685_ADDRESS_2 0x42
#define PCA9685_ADDRESS_3 0x43
Adafruit_PWMServoDriver pwm0 = Adafruit_PWMServoDriver(PCA9685_ADDRESS_0, Wire);
Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(PCA9685_ADDRESS_1, Wire);
Adafruit_PWMServoDriver pwm2 = Adafruit_PWMServoDriver(PCA9685_ADDRESS_2, Wire);
Adafruit_PWMServoDriver pwm3 = Adafruit_PWMServoDriver(PCA9685_ADDRESS_3, Wire);
Adafruit_PWMServoDriver PWMs[number_of_PWMS] = {pwm0, pwm1, pwm2, pwm3};
int color_black = 0;
int color_blue = 1;
int color_yellow = 2;
int color_green = 3;
int color_white = 4;
int color_red = 5;
int color[][5] = {
{00, 00, 0},
{00, 00, 255},
{255, 255, 0},
{00, 255, 0},
{255, 255, 255},
{255, 00, 0}
};
bool run_trafficAdvisorL = true;
bool run_front_alt_blue_red=true;
bool run_trafficAdvisorR = true;
bool run_trafficAdvisorM = true;
uint8_t trafficAdvisorL_pin = 11;
uint8_t trafficAdvisorR_pin = 10;
uint8_t trafficAdvisorM_pin= 9;
/*
int blank_pattern[player_limit][number_of_leds]=
{
{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00},
{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00},
};
*/
uint8_t trafficAdvisorR[player_limit][number_of_leds]=
{
{00,00,00,00,00,00,00,00,00,00, 00,00,-1,-1,-1,-1,-1,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00,00,-1,-1,-1,-1,02,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00,00,-1,-1,-1,02,02,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00,00,-1,-1,02,02,02,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00,00,-1,02,02,02,02,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,02,02,02,02,00,00},
};
uint8_t trafficAdvisorL[player_limit][number_of_leds]=
{
{00,00,00,00,00,00,00,00,00,00, 00,00,02,-1,-1,-1,-1,-1,00,0},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,-1,-1,-1,-1,00,0},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,02,-1,-1,-1,00,0},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,02,02,-1,-1,00,0},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,02,02,02,-1,00,0},
{00,00,00,00,00,00,00,00,00,00, 00,00,02,02,02,02,02,02,00,0},
};
uint8_t trafficAdvisorM[player_limit][number_of_leds]=
{
{00,00,00,00,00,00,00,00,00,00, 00, 00,-1,-1,02,02,-1,-1,00,00},
{00,00,00,00,00,00,00,00,00,00, 00, 00,-1,02,02,02,02,-1,00,00},
{00,00,00,00,00,00,00,00,00,00, 00, 00,02,02,02,02,02,02,00,00},
{00,00,00,00,00,00,00,00,00,00, 00, 00,-1,-1,02,02,-1,-1,00,00},
{00,00,00,00,00,00,00,00,00,00, 00, 00,-1,02,02,02,02,-1,00,00},
{00,00,00,00,00,00,00,00,00,00, 00, 00,02,02,02,02,02,02,00,00},
};
uint8_t front_alt_blue_red[player_limit][number_of_leds]=
{
{00,01,05,01,05,01,05,01,05,00, 00,00,00,00,00,00,00,00,00,00},
{00,05,01,05,01,05,01,05,01,00, 00,00,00,00,00,00,00,00,00,00},
{00,01,05,01,05,01,05,01,05,00, 00,00,00,00,00,00,00,00,00,00},
{00,05,01,05,01,05,01,05,01,00, 00,00,00,00,00,00,00,00,00,00},
{00,01,05,01,05,01,05,01,05,00, 00,00,00,00,00,00,00,00,00,00},
{00,05,01,05,01,05,01,05,01,00, 00,00,00,00,00,00,00,00,00,00},
};
uint8_t silly_funny_pattern_01[player_limit][number_of_leds]=
{
{05,05,05,05,05,01,01,01,01,01, 01,01,01,01,01,05,05,05,05,05},
{01,01,01,01,01,05,05,05,05,05, 05,05,05,05,05,01,01,01,01,01},
{05,05,05,05,05,01,01,01,01,01, 01,01,01,01,01,05,05,05,05,05},
{01,01,01,01,01,05,05,05,05,05, 05,05,05,05,05,01,01,01,01,01},
{05,05,05,05,05,01,01,01,01,01, 01,01,01,01,01,05,05,05,05,05},
{01,01,01,01,01,05,05,05,05,05, 05,05,05,05,05,01,01,01,01,01},
};
void setup() {
//Serial.begin(9600);
// starts the PWM units and sets the Freq
for ( int x = 0; x < number_of_PWMS; x++)
{
PWMs[x].begin();
PWMs[x].setPWMFreq(1000);
}
// this just fills the array with the values we want
int counter = 0; // this counter keeps track of the led number
for ( int pwm_unit = 0; pwm_unit < number_of_PWMS; pwm_unit++)
{
// we start at x = 0
// for each we also do this
for (int port = 0; port < 5; port++)
{
myleds_PWM_unit[counter] = pwm_unit;
myleds_port_number[counter] = port;
counter++;
}
}
// your delay - assume for chip settle
delay(10);
pinMode(trafficAdvisorL_pin, INPUT_PULLUP);
pinMode(trafficAdvisorR_pin, INPUT_PULLUP);
pinMode(trafficAdvisorM_pin, INPUT_PULLUP);
}
/*
int blank_pattern[player_limit][number_of_leds]=
{
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00},
{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00},
{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00},
{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00},
{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00},
};
*/
void loop() {
//Serial.println("Start Loop") ;
// read switches and set logic
run_trafficAdvisorL = false;
run_front_alt_blue_red=false;
run_trafficAdvisorR = false;
run_trafficAdvisorM=false;
if(digitalRead(trafficAdvisorL_pin) == 1) run_trafficAdvisorL = true;
if(digitalRead(trafficAdvisorR_pin) == 1) run_trafficAdvisorR = true;
if(digitalRead(trafficAdvisorM_pin) == 1) run_trafficAdvisorM = true;
for ( int player_run=0; player_run < player_limit; player_run++)
{
int x;
//zero the player run
for (x= 0 ;x < 20;x++)
{
player[player_run][x]=0;
}
//Serial.print("Run ") ;
//Serial.print(player_run) ;
//Serial.println(" Cleared") ;
{
if (silly_funny_pattern_01)
{
//global_delay = 100;
for (int x= 0;x < 20;x++)
{
// see
if (silly_funny_pattern_01[player_run][x] !=0)
{
player[player_run][x]=silly_funny_pattern_01[player_run][x];
}
}
}
if(run_trafficAdvisorR)
{
{
for (int x= 0;x < 20;x++)
{
// see
if (trafficAdvisorR[player_run][x] !=0)
{
player[player_run][x]=trafficAdvisorR[player_run][x];
}
}
}
}
if(run_trafficAdvisorR)
{
{
for (int x= 0;x < 20;x++)
{
// see
if (trafficAdvisorL[player_run][x] !=0)
{
player[player_run][x]=trafficAdvisorL[player_run][x];
}
}
}
}
if(run_trafficAdvisorM)
{
{
for (int x= 0;x < 20;x++)
{
// see
if (trafficAdvisorM
[player_run][x] !=0)
{
player[player_run][x]=trafficAdvisorM
[player_run][x];
}
}
}
}
// completed all the pattern insertions - show it
for ( int x = 0; x < 20; x++)
{
setLED(x, player[player_run][x]);
}
////Serial.println(digitalRead(11));
delay(global_delay);
}
delay(75); // chip settle ?
}
}
void set_player( int line_number, uint8_t selected_array[5][20] )
{
for (int x = 0; x < 20; x++)
{
if (selected_array[line_number][x] != 0) // <--- if the pattern is 0 -
// we dont do any thing
{
player[line_number][x] = selected_array[line_number][x];
}
}
}
void setLED(uint8_t lednumber, uint8_t color_num) {
// this sets the color based on the number that comes in (color_num)
int Rvalue = color[color_num][0];
int Gvalue = color[color_num][1];
int Bvalue = color[color_num][2];
// this is your code to map to 4096 from 255
uint16_t redPWM = (Rvalue == 0) ? 4096 : map(Rvalue, 0, 255, 0, 4095);
uint16_t greenPWM = (Gvalue == 0) ? 4096 : map(Gvalue, 0, 255, 0, 4095);
uint16_t bluePWM = (Bvalue == 0) ? 4096 : map(Bvalue, 0, 255, 0, 4095);
// this is where the actual PWM chip and LED are set
PWMs[myleds_PWM_unit[lednumber]].setPWM((myleds_port_number[lednumber]) * 3, 4096, redPWM);
PWMs[myleds_PWM_unit[lednumber]].setPWM((myleds_port_number[lednumber]) * 3 + 1, 4096, greenPWM);
PWMs[myleds_PWM_unit[lednumber]].setPWM((myleds_port_number[lednumber]) * 3 + 2, 4096, bluePWM);
//delay(20);
}
1----2----3----4---5----6----7----8
9
10
18---17---16---15---14---13---12---11
0
19