Monday, March 1, 2010

Combining some new concepts

Working with some ideas i had yesterday with the 7 segment display and the LDRs. I wrote this small program this morning that runs a pattern across the display (this pattern is stored in an array) and the speed at which the pattern is run through is decided by an LDR:

int pattern[8] = {10,11,12,13,7,8,9,13};
int pri;
int sec;
int tri;
int rate;

void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
pinMode(9,OUTPUT);
pinMode(8,OUTPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);
}

void loop(){
for (int i = 0; i < 8; i++){
digitalWrite(pattern[pri],0);
digitalWrite(pattern[sec],0);
digitalWrite(pattern[tri],0);
tri = sec;
sec = pri;
pri = i;
digitalWrite(pattern[pri],1);
digitalWrite(pattern[sec],1);
digitalWrite(pattern[tri],1);
rate = analogRead(0);
delay(rate);
}
}

The bread board is set out identical to dice part 2 except the button is replaced with an LDR.

No comments:

Post a Comment