Saturday, March 12, 2011

Arduino Stuff, attempt 1

Went to the electronic's store on goodman and bought a bunch of wire and LEDs so I could just start messing around. Installed the software and drivers and booted up the program, did the blink test which was pretty straightforward. I decided that I wanted to make an array of LEDs that could be lit and dimmed individually. To do this, I started out with the simplest, 2X2. I've got 2 wires from pins 6 and 7 (anode) to control the rows, and 2 from 8 and 9 (cathode) to control the columns. To make a light turn on, I just set the power to high on the row(anode) pins, and low on column(cathode) pins so that there is a flow of electricity. To turn a light off, either apply a low charge to the row pin, or if another light in that row should be on, apply a high charge to that column. If the row and column have the same value, there will be no electricity flow. Anyways, here's the code I've got working so far, I didn't get frames working yet but maybe next time.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/
#define DIM 2
#define DIM1 (DIM-1)
typedef byte Frame[DIM];
int cols[DIM]={8,9};
int rows[DIM]={6,7};
int pinVals[DIM][DIM];
boolean lit=false;
Frame blankFrame={B00,
B00};
//Frame fullFrame={B11,
// B11};
byte *currentFrame=blankFrame;
int curFrame=0;
Frame Frames[4]={
{B10,
B00},
{B01,
B00},
{B00,
B10},
{B00,
B01}};
void setFrame()
{
curFrame++;
if(curFrame>4)
curFrame=0;
currentFrame=Frames[curFrame];

}
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
int i;
for(i=0;i {
pinMode(cols[i],OUTPUT);
pinMode(rows[i],OUTPUT);
}
}

void loop() {
int c=HIGH;
int r=LOW;
if(lit)
{
c=LOW;
r=HIGH;
}
//Just tests connections, doesn't use frames
int i;
for (i=0;i < DIM;i++)
{
digitalWrite(rows[i],LOW);
for (int j=0;j < DIM;j++) {
digitalWrite(cols[j],HIGH);
delay(250);
digitalWrite(cols[j],LOW);
}
digitalWrite(rows[i],HIGH);
}
setFrame();
delay(400); // wait for a second
}

No comments:

Post a Comment