- Sat Feb 18, 2017 9:46 am
#193469
Hello,
intro: I am a newbie in electronics, my project is to make a midi controller. I have done most of the parts.
I bought the button pad PCB 4x4 because it is cheaper than two 2x2 PCB. i have 2 Button pad rubber 2x2 (I only need 2 rows and 4 columns) to have 8 buttons.
my problem:
I followed this tutorial : https://learn.sparkfun.com/tutorials/bu ... hrome-leds .
I am blocked in the tutorial for the first exercice.
When I launch the code, nothing happen.
I use monochrome Led instead of RGB, I connect it like on the picture. (the only difference?)
I changed the code at line 5 and 6 to match my connections to my arduino uno.
"
static const uint8_t ledcolumnpins[NUM_LED_COLUMNS] = {8,9,10,11};
static const uint8_t colorpins[NUM_LED_ROWS] = {2,3,4,5};
"
Could you help me please to make it works ?
Have you any idea of a more simple code just to test the LED ?
pictures:
intro: I am a newbie in electronics, my project is to make a midi controller. I have done most of the parts.
I bought the button pad PCB 4x4 because it is cheaper than two 2x2 PCB. i have 2 Button pad rubber 2x2 (I only need 2 rows and 4 columns) to have 8 buttons.
my problem:
I followed this tutorial : https://learn.sparkfun.com/tutorials/bu ... hrome-leds .
I am blocked in the tutorial for the first exercice.
When I launch the code, nothing happen.
I use monochrome Led instead of RGB, I connect it like on the picture. (the only difference?)
I changed the code at line 5 and 6 to match my connections to my arduino uno.
"
static const uint8_t ledcolumnpins[NUM_LED_COLUMNS] = {8,9,10,11};
static const uint8_t colorpins[NUM_LED_ROWS] = {2,3,4,5};
"
Code: Select all
Thanks for your attention.//config variables
#define NUM_LED_COLUMNS (4)
#define NUM_LED_ROWS (4)
#define NUM_COLORS (1)
// Global variables
static bool LED_buffer[NUM_LED_COLUMNS][NUM_LED_ROWS];
static int32_t next_advance;
static uint8_t led_index;
static const uint8_t ledcolumnpins[NUM_LED_COLUMNS] = {8,9,10,11};
static const uint8_t colorpins[NUM_LED_ROWS] = {2,3,4,5};
static void setuppins()
{
uint8_t i;
// initialize all of the output pins
// LED column lines
for(i = 0; i < NUM_LED_COLUMNS; i++)
{
pinMode(ledcolumnpins[i], OUTPUT);
// with nothing selected by default
digitalWrite(ledcolumnpins[i], HIGH);
}
// LED row lines
for(i = 0; i < NUM_LED_ROWS; i++)
{
pinMode(colorpins[i], OUTPUT);
// with nothing driven by default
digitalWrite(colorpins[i], LOW);
}
}
static void scan()
{
static uint8_t current = 0;
uint8_t val;
uint8_t i, j;
// Select a column
digitalWrite(ledcolumnpins[current], LOW);
// write the row pins
for(i = 0; i < NUM_LED_ROWS; i++)
{
if(LED_buffer[current][i])
{
digitalWrite(colorpins[i], HIGH);
}
}
delay(1);
digitalWrite(ledcolumnpins[current], HIGH);
for(i = 0; i < NUM_LED_ROWS; i++)
{
digitalWrite(colorpins[i], LOW);
}
// Move on to the next column
current++;
if (current >= NUM_LED_COLUMNS)
{
current = 0;
}
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
Serial.print("Starting Setup...");
// setup hardware
setuppins();
// init global variables
next_advance = millis() + 1000;
led_index = 0;
// Initialize the LED display array
for(uint8_t i = 0; i < NUM_LED_COLUMNS; i++)
{
for(uint8_t j = 0; j < NUM_LED_ROWS; j++)
{
LED_buffer[i][j] = false;
}
}
// Set the first LED in the buffer on
LED_buffer[0][0] = true;
Serial.println("Setup Complete.");
}
void loop()
{
// put your main code here, to run repeatedly:
scan();
if(millis() >= next_advance)
{
next_advance = millis()+1000;
LED_buffer[led_index/NUM_LED_COLUMNS][led_index%NUM_LED_COLUMNS] = false;
led_index++;
led_index %= (NUM_LED_COLUMNS * NUM_LED_ROWS);
LED_buffer[led_index/NUM_LED_COLUMNS][led_index%NUM_LED_COLUMNS] = true;
}
}
Could you help me please to make it works ?
Have you any idea of a more simple code just to test the LED ?
pictures: