Monday, January 4, 2010

Arduino code for four lasers

This is some of the code I am working on for the MFA project that I mentioned in the last post. Right now I simply have four photocells, each controlling an LED. Next week I plan to get one of these so that I can replace the lights with a triggered sound. This might require significant reworking of the code... we'll see.

First the video, then the code:



/*
Created 11 Dec 2009
By J Howell
modified 14 Dec 2009

*/

int ledPinA = 10; // LED connected to digital pin 10
int ledPinB = 11; // LED connected to digital pin 11
int ledPinC = 6; // LED connected to digital pin 11
int ledPinD = 5; // LED connected to digital pin 11
int val0; // define variable for photoresistor 0
int val1; // define variable for photoresistor 1
int val2; // define variable for photoresistor 1
int val3; // define variable for photoresistor 1
int ledBrightness; //


void setup()
{
Serial.begin(9600); // sets the serial port to 9600
}

void loop()
{
val0 = analogRead(0); // read analog input pin 0
val1 = analogRead(1); // read analog input pin 1
val2 = analogRead(2); // read analog input pin 2
val3 = analogRead(3); // read analog input pin 3

if( val0 < 400){
// fade in from min to max in increments of 1 points:
for(int fadeValue0 = 0 ; fadeValue0 <= 255; fadeValue0 +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinA, -(fadeValue0));
}
}
else{
digitalWrite(ledPinA, LOW);
delay(10);
}
if( val1 < 400){
// fade in from min to max in increments of 1 points:
for(int fadeValue0 = 0 ; fadeValue0 <= 255; fadeValue0 +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinB, -(fadeValue0));
}
}
else{
digitalWrite(ledPinB, LOW);
delay(10);
}

if( val2 < 400){
// fade in from min to max in increments of 1 points:
for(int fadeValue1 = 0 ; fadeValue1 <= 255; fadeValue1 +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinC, -(fadeValue1));
}
}
else{
digitalWrite(ledPinC, LOW);
delay(10);
}
if( val3 < 400){
// fade in from min to max in increments of 1 points:
for(int fadeValue0 = 0 ; fadeValue0 <= 255; fadeValue0 +=1) {
// sets the value (range from 0 to 255):
analogWrite(ledPinD, -(fadeValue0));
}
}
else{
digitalWrite(ledPinD, LOW);
}
}

1 comment:

Anonymous said...

Infatuation casinos? improvement advance onto this advanced [url=http://www.realcazinoz.com]casino[/url] advisor and wing it belittle online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also strengthen our up to the the changeless sec [url=http://freecasinogames2010.webs.com]casino[/url] hold at http://freecasinogames2010.webs.com and ripe in true to stretch demanding currency !
another unsurpassed [url=http://www.ttittancasino.com]casino spiele[/url] authority is www.ttittancasino.com , because german gamblers, subsection in unrestrained online casino bonus.