pinMode (s0, OUTPUT); // set up our sensor
pinMode (s1, OUTPUT); // pins to control
pinMode (s2, OUTPUT); // Color Filter.
pinMode (oe,OUTPUT);
pinMode (s3, OUTPUT);
I'd rather see all 4 sN pins set together.
Some blank lines to separate logical bits of code would be helpful, too.
Not using blank lines where not needed would be helpful, too. (The one right after setup()'s open brace is annoying.)
digitalWrite(s0,LOW); // Set scaling here.
digitalWrite(s1,HIGH);
It might be obvious to you how that sets scaling, but it isn't obvious to anyone else.
// ****************************************************
// This is our interupt service routine.
// ****************************************************
void sensorisr ()
{
sensorpulse ++; // Add 1 to our pulse count.
}
If you are going to use comments, and I strongly recommend that you do, stating the obvious is a waste of time.
sensorpulse (I hate names all in lower case) is used by the ISR and other functions, but is not declared volatile.
unsigned long getcolor (int color,unsigned long colormillis)
Spacesbetweenargumentsarenice.
do
{
currentpulse = sensorpulse;
}
while ((millis() - colormillis) < 250); // check for 1/4 sencond;
During this code, the compiler can see that sensorpulse never changes (since it is not declared volatile). As a result, this loop will never set a different value for currentpulse (camelCase was invented for a reason!), so, you might as well have used delay(250); here.
colormillis is a lousy name. Yes, the variable has something to do with time, but what, exactly? startTime would make more sense.
if (color == 1)
{
}
if (color == 2)
{
}
if (color == 3)
{
}
if (color == 4)
{
}
Is there any situation where more than one of these blocks will be executed? The else if statement should be deployed, here.
You have very similar actions in each block. A function, instead of cut and paste, would have been better.
void loop()
{
displaysensor();
getsensor();
}
Display some values, then get some values to display. Hmmm, something's wrong with this picture.