« ADVANCED MICROCONTROLLER SUCCESS | Main | ICM FINAL - PROPAGANDA P-COMP »

LIGHT DIMMER RANDOM CODE

This piece of code is the last code i wrote to generate a random series of values to try to achieve the flickering effect i was after.

Unfortunately the random number generator in Arduino isn't very good, like in most cases, so i am actually right now manually working out the kind of effect that I want to then figure out what math is necessary.

A more transitional and smooth curve is necessary and i am working out a piece of code for that as well.

/*
DAC pins: digital I/O 6 - 13
*/
int time;
long randNumber;

void setup() {
Serial.begin(9600);
//set pins as outputs:
for (int i = 6; i < 14; i++) {
pinMode(i, OUTPUT);
}
time = millis();
randomSeed(time);
}

void loop() {
setDAC(random(255));
delay(random(1000));
delay (10);
}

void setDAC(byte DAClevel) {
byte thisValue = 0;
for (int k = 6; k < 14; k++) {
// read the appropriate bit from DAClevel:
if ( (DAClevel & (1<<(k-6))) >0 ) {
thisValue= 1;
}
else {
thisValue= 0;
}
// turn on or off the pin based on the value of the bit:
// Serial.print(thisValue, DEC);
digitalWrite(k, thisValue);
}
Serial.println(DAClevel, DEC);
}

I will soon update the blog with some video of the light dimming transitions.

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~bp432/cgi-bin/mt/mt-tb.cgi/44