Show Posts
Pages: [1] 2 3 ... 14
1  Using Arduino / Programming Questions / Re: array index on: September 16, 2012, 02:03:30 pm
9000 characters apparently

Code:
// ****************************************************
//          This function sets pin modes
// Depending on the color filter defined below.
// 1 = red filter
// 2 = blue filter
// 3 = no color filter
// 4 = green filter
// ****************************************************
void colormode ( int color)
{
  if (color == red)
  {
    digitalWrite ( s2, LOW); // red
    digitalWrite ( s3, LOW);
  }
  if (color == blue)
  {
    digitalWrite ( s2, LOW); // BLue filter
    digitalWrite ( s3, HIGH);
  }
  if (color == nocolor)
  {
    digitalWrite ( s2, HIGH); // clear filter or no color
    digitalWrite ( s3, LOW);
  }
  if (color == green)
  {
    digitalWrite ( s2, HIGH); // greeen
    digitalWrite ( s3, HIGH);
  }
} // colormode



// ****************************************************
//          This function returns a value
// Depending on the color filter defined below.
// 0 ambient color
// 1 = red filter
// 2 = blue filter
// 3 = no color filter
// 4 = green filter
// ****************************************************
unsigned long  getcolor (int color)
{
  unsigned long colorpulse = 0; // pulse count to return
  sensorpulse = 0; // make sure sensor pulse starts at zero.
  colormillis = millis(); // record current millis
  if ((color >=1) && (color <= 4))
  {
    colormode (color);
  }
  else
  {
    colorpulse = 0; // return zero if we  ask for calor value that is not 1,2,3,4
  }
  digitalWrite(oe,LOW); // turn sensor on
  do 
  {
    // do nothing until wait time expires
  }
  while ((millis() - colormillis)  < waittime);
  digitalWrite (oe, HIGH); // turn sensor off.
  colorpulse = sensorpulse;
  sensorpulse = 0; // reset value of sensor pulse
  return colorpulse;
} // end getcolor



// ****************************************************
// set the static portion of our display up
// This does not change so there is no reason to display it over and over
// ****************************************************
void scrnsetup()
{
  lcd.setCursor(0,0);
  lcd.print("R:");
  lcd.setCursor(7,0);
  lcd.print("B:");
  lcd.setCursor(0,1);
  lcd.print("G:");
  lcd.setCursor(7,1);
  lcd.print("N:");
} // end scrnsetup


// ****************************************************
// Display our non static values to the lcd display
//
//
// ****************************************************
void displaylcd()
{
  lcd.setCursor(3,0);
  lcd.print("    ");
  lcd.setCursor(3,0);
  lcd.print(colorpulsecount[red]);
  lcd.setCursor ( 10,0);
  lcd.print("    ");
  lcd.setCursor ( 10,0);
  lcd.print(colorpulsecount[blue]);
  lcd.setCursor(3,1);
  lcd.print("    ");
  lcd.setCursor(3,1);
  lcd.print(colorpulsecount[green]);
  lcd.setCursor ( 10,1);
  lcd.print("    ");
  lcd.setCursor ( 10,1);
  lcd.print(colorpulsecount[nocolor]);
} // end displaylcd



//************************************************
// Here we just display the sensor value to serial minitor
// this procedure echos our sensor pulse count
// to the seial monitor.
//************************************************
void dispserial()
{
  Serial.print ( "red :");
  Serial.println (colorpulsecount[red]);
  Serial.print ( "Blue :");
  Serial.println (colorpulsecount[blue]);
  Serial.print ( "CL or NC :");
  Serial.println (colorpulsecount[nocolor]);
  Serial.print ( "Green :");
  Serial.println (colorpulsecount[green]);
  Serial.println ("-----------");
} // end dispserial


// ****************************************************
// This function toggles LEDs on depending on the value it is sent.
// 0 = ambient
// 1 = red
// 2 = blue
// 3 = no color
// 4 = green
// ****************************************************
void ledcontrol ( int color)
{
  if (color == 0) // turn all leds off
  {
    digitalWrite(ledpin,HIGH);
    digitalWrite(redrgbledpin,HIGH);
    digitalWrite(bluergbledpin,HIGH);
    digitalWrite(greenrgbledpin,HIGH);
  }
  if (color == 1) // turn red led on
  {
    digitalWrite(ledpin,HIGH);
    digitalWrite(redrgbledpin,LOW);
    digitalWrite(bluergbledpin,HIGH);
    digitalWrite(greenrgbledpin,HIGH);
  }
  if (color == 2) // turn blue led on
  {
    digitalWrite(ledpin,HIGH);
    digitalWrite(redrgbledpin,HIGH);
    digitalWrite(bluergbledpin,LOW);
    digitalWrite(greenrgbledpin,HIGH);
  }
  if (color == 3) // turn white led on
  {
    digitalWrite(ledpin,LOW);
    digitalWrite(redrgbledpin,HIGH);
    digitalWrite(bluergbledpin,HIGH);
    digitalWrite(greenrgbledpin,HIGH);
  }
  if (color == 4) // turn green led on
  {
    digitalWrite(ledpin,HIGH);
    digitalWrite(redrgbledpin,HIGH);
    digitalWrite(bluergbledpin,HIGH);
    digitalWrite(greenrgbledpin,LOW);
  }
} // end ledcontrol
2  Using Arduino / Programming Questions / Re: array index on: September 16, 2012, 02:02:34 pm
my sketch

Code:
/*
TCS3200 / 3210  COLOR sensor from TAOS.
 Written By Michael King
 Copiertalk.com
 Creative commons share alike.
 
 The sensor provides a pulse  depending on the value of the color filter
 , frequency scaling desired as well as the output enable pin being low.
 We are going to use an interupt on pin 18 to count the number of pulses in
 a given amount of time. We will use the values returned to try and
 and tell the color the sensor is "seeing" at the moment.
 
 We will use these pin settings in our program to fine tume the sensor to
 our needs.
 
 s0 and s1 set the Frequency scaling
 s0 = low / s1 = low is power down mode for the sensor
 s0 = low / s1 = hihg 2% scale
 s0 = high / s1 = low 20% scale
 s0 = high / s1 = high 100% scale
 
 s2 and s3 set the color filter of the sensor
 s2 = low /  s3 = low red filter
 s2 = low / s3 = high blue filter
 s2 = high / s3 = low Clear or no filter
 s2 = high / s3 = high green filter
 
 Some breakout boards use an LED to illuminate the object and
 we will use pin 13 to control this led on the breakout board that I
 am using.
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(53, 49, 41, 43, 45, 47);

unsigned long colormillis = millis(); // millis for color function


// ****************************************************
// s0 and s1 set the Frequency scaling
// s0 = low / s1 = low is power down mode for the sensor
// s0 = low / s1 = hihg 2% scale
// s0 = high / s1 = low 20% scale
// s0 = high / s1 = high 100% scale
// s2 and s3 set the color filter of the sensor
// s2 = low /  s3 = low red filter
// s2 = low / s3 = high blue filter
// s2 = high / s3 = low Clear or no filter
// s2 = high / s3 = high green filter
// ****************************************************
const int s0 = 30; // Pins for our color sensor filters
const int s1 = 31; // and our scaling. You can use any digital pins.
const int s2 = 32;
const int s3 = 33;
const int oe = 35;

const int ledpin = 13; // pin to control sensor led on /off
const int redrgbledpin = 5;
const int bluergbledpin = 7;
const int greenrgbledpin = 6;

const int ambient = 0; // constant vales to represent color
const int red = 1;
const int blue = 2;
const int nocolor = 3;
const int green = 4;

const unsigned long waittime = 25; // time to take sensor reading

// These variables are to store the pulse count returned by
// our interupt service routine. we assign them with the function call
unsigned long colorpulsecount[5];


volatile unsigned long sensorpulse = 0; // This value will be changed
// by the service routine and
// then taken and asigned to another
// variable in our program depending on the
// color filter in use  


// ****************************************************
// Setup function
// This is executed once at the start of our program
// It sets up our pins for our sensor, our lcd and defines our
// initial values of pin modes and outut levels.
// ****************************************************
void setup()
{
  sensorpulse = 0; // I want to make sure this value starts at zero

  pinMode (redrgbledpin,OUTPUT); // Set  leds
  pinMode (bluergbledpin,OUTPUT); // pinmodes as
  pinMode (greenrgbledpin,OUTPUT); // OUTPUTS
  pinMode(ledpin,OUTPUT);

  pinMode (s0, OUTPUT); // set up our sensor  
  pinMode (s1, OUTPUT); // pins to control scaling

  pinMode (s2, OUTPUT); // set up our sensor pins
  pinMode (s3, OUTPUT); // to control color filter

  pinMode (oe,OUTPUT); // output enable pin for our color  sensor
  digitalWrite(oe,LOW); // low is enable / high is disabled

  digitalWrite(s0,HIGH); // Set scaling here.
  digitalWrite(s1,LOW); // s0 high and s1 low is 20% scale


  digitalWrite(ledpin,HIGH); // Pin to control LED on sensor if needed
  digitalWrite(redrgbledpin,HIGH);
  digitalWrite(bluergbledpin,HIGH);
  digitalWrite(greenrgbledpin,HIGH);

  attachInterrupt(5, sensorisr, RISING); // Asign our interupt to the function and set to rising

  lcd.begin(16, 2); // set up the LCD's number of columns and rows:
  Serial.begin(9600); // start serial
  scrnsetup(); // write static portion of our lcd.
}// end setup


// ****************************************************
//         This is our interupt service routine.
// Any time an interupt happens on the specified pin
// we increment the value of sensorpule and leave.
// Thats all we do here..
// ****************************************************
void sensorisr ()
{
  sensorpulse ++; // Add 1 to our pulse count.
} // end sensorisr



// ****************************************************
//          Get the color values from our sensor
// 0 = ambient color
// 1 = red filter
// 2 = blue filter
// 3 = no color filter
// 4 = green filter
// ****************************************************
void getcolorval() // Get the sensor values;
{
  ledcontrol (red);
  delay (250); // these will not stay here. I just want to watch the leds
  colorpulsecount[red] = getcolor (red);
  ledcontrol (blue);
  delay (250);
  colorpulsecount[blue] = getcolor (blue);
  ledcontrol (green);
  delay (250);
  colorpulsecount[nocolor] = getcolor (nocolor);
  ledcontrol (nocolor);
  delay(250);
  colorpulsecount[green] = getcolor (green);
  ledcontrol (ambient);
  delay(250);
  colorpulsecount[ambient] = getcolor (ambient);
} // end getcolorval




// ****************************************************
//         Our Main loop over and over again
// ****************************************************
void loop()
{
  getcolorval();
  displaylcd();
  dispserial();
  delay(250); // So we can read the display
}// end loop


3  Using Arduino / Programming Questions / Re: array index on: September 16, 2012, 01:56:20 pm
If you're really determined to do that you could declare a pointer and set it to the address of the [-1] element of your array and then dereference the pointer as if it was an array. Accessed via the pointer, all the element indices would be one higher than normal (it would go from 1 .. n rather than 0 .. n-1). I think it's a spectacularly bad idea, but it would achieve the effect you asked for.

Perhaps if you explain what you hope to achieve through this we could suggest a way to achieve it that isn't so nasty.

When I started my sketch I defined constants to represent colors the sensor I am using could represent.
1 was going to be red, 2 was going to be blue, 3 was going to be white and 4 was going to represent green.

As I have written the program I started to want to save the color values in a variable and the sensible way was to declare an array of color values. I had already used the above mothod extensively in my scetch and  I did not allow for a zero value to represent a color. I already have a bunch coded and was trying to find an easy way out is all.

I think I found a better idea.
4  Using Arduino / Programming Questions / Re: array index on: September 16, 2012, 01:23:54 pm
Thanks for the help anyway  smiley-cool
5  Using Arduino / Programming Questions / Re: array index on: September 16, 2012, 01:23:26 pm
I am just going to define the array with 5 elements instead of 4 and use the extra element for storing information when no leds are on.

I am playing with an rgb color sensor and I was going to store the values for each color when reflected with light from an RGB LED in the array.

1 was going to represent the red led on
2.. blue led on
3... white led on
4... green led on


it never occured to me that I may want the color values with no leds on.  I will just use the fifth element to store the color information with no leds on or the ambient light in the room.

I will just add for
0... no leds are on
6  Using Arduino / Programming Questions / array index on: September 16, 2012, 12:26:56 pm
An array index usually starts with a
  • .

Is there any way to start an array with the first cell being [1] instead of
  • ;
7  Using Arduino / Programming Questions / Re: critique programming for tcs3200 / tcs3210 color sensor. on: September 12, 2012, 07:44:26 pm
Code:
/*
TCS3200 / 3210  COLOR sensor from TAOS.
 Written By Michael King
 Copiertalk.com
 Creative commons share alike.
 
 The sensor provides a pulse  depending on the value of the color filter
 , frequency scaling desired as well as the output enable pin being low.
 We are going to use an interupt on pin 2 to count the number of pulses in
 a given amount of time. We will use the values returned to try and
 and tell the color the sensor is "seeing" at the moment.
 
 We will use these pin settings in our program to fine tume the sensor to
 our needs.
 
 s0 and s1 set the Frequency scaling
 s0 = low / s1 = low is power down mode for the sensor
 s0 = low / s1 = hihg 2% scale
 s0 = high / s1 = low 20% scale
 s0 = high / s1 = high 100% scale
 
 s2 and s3 set the color filter of the sensor
 s2 = low /  s3 = low red filter
 s2 = low / s3 = high blue filter
 s2 = high / s3 = low Clear or no filter
 s2 = high / s3 = high green filter
 
 Some breakout boards use an LED to illuminate the object and
 we will use pin 13 to control this led on the breakout board that I
 am using.
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(53, 49, 41, 43, 45, 47);

int whatcolor = 0; // what color are we testing
unsigned long   currentmillis =  millis();
unsigned long   oldmillis = millis();


// ****************************************************
// s0 and s1 set the Frequency scaling
// s0 = low / s1 = low is power down mode for the sensor
// s0 = low / s1 = hihg 2% scale
// s0 = high / s1 = low 20% scale
// s0 = high / s1 = high 100% scale
// s2 and s3 set the color filter of the sensor
// s2 = low /  s3 = low red filter
// s2 = low / s3 = high blue filter
// s2 = high / s3 = low Clear or no filter
// s2 = high / s3 = high green filter
// ****************************************************
int s0 = 30; // Pins for our color sensor filters
int s1 = 31; // and our scaling. You can use any digital pins.
int s2 = 32;
int s3 = 33;
int oe = 35;
int ledpin = 13; // pin to control sensor led on /off
// These variables are to store the pulse count returned by
// our interupt service routine. we assign them with the function call
//
unsigned long red = 0;
unsigned long blue = 0;
unsigned long green = 0;
unsigned long nocolor = 0;
volatile unsigned long sensorpulse = 0; // This value will be changed
// by the service routine and
// then taken and asigned to another
// variable in our program depending on the
// color filter in use   


// ****************************************************
// Setup function
// This is executed once at the start of our program
// It sets up our pins for our sensor, our lcd and defines our
// initial values of pin modes and outut levels.
// ****************************************************
void setup()
{
  sensorpulse = 0; // I want to make sure this value starts at zero

  pinMode (s0, OUTPUT); // set up our sensor 
  pinMode (s1, OUTPUT); // pins to control scaling

  pinMode (s2, OUTPUT); // set up our sensor pins
  pinMode (s3, OUTPUT); // to control color filter

  pinMode (oe,OUTPUT); // output enable pin for our color  sensor
  digitalWrite(oe,LOW); // low is enable / high is disabled

  digitalWrite(s0,LOW); // Set scaling here.
  digitalWrite(s1,HIGH); // s0 high and s1 low is 2% scale

  digitalWrite(ledpin,HIGH); // Pin to control LED on sensor if needed

  attachInterrupt(0, sensorisr, RISING); // Asign our interupt to the function and set to rising

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  scrnsetup(); // write static portion of our lcd.
}


// ****************************************************
//         This is our interupt service routine.
// ****************************************************
void sensorisr ()
{
  sensorpulse ++; // Add 1 to our pulse count.
}

// ****************************************************
//          This function returns a value
// Depending on the color filter defined below.
// 1 = red filter
// 2 = blue filter
// 3 = green filter
// 4 = no color filter
// ****************************************************
unsigned long  getcolor (int color , unsigned long colormillis)
{
  unsigned long currentpulse;
  digitalWrite(ledpin,LOW); // turn leds on
  if (color == 1)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, LOW); // red
    digitalWrite ( s3, LOW);
    do 
    {
      currentpulse = sensorpulse;
    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }
  if (color == 2)
  {
    digitalWrite(oe,LOW); // Turn Sensor on
    digitalWrite ( s2, LOW); // BLue filter
    digitalWrite ( s3, HIGH);
    do 
    {
      currentpulse = sensorpulse;
    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }

  if (color == 3)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, HIGH); // greeen
    digitalWrite ( s3, HIGH);
    do 
    {
      currentpulse = sensorpulse;
    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }

  if (color == 4)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, HIGH); // clear filter or no color
    digitalWrite ( s3, LOW);
    do 
    {
      currentpulse = sensorpulse;
    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }
  sensorpulse=0; // reset our pulse count prior to leaving
  digitalWrite (oe,HIGH); // Turn sensor off
  // digitalWrite(ledpin,HIGH); // turn leds off if needed
  return currentpulse;
}


// ****************************************************
// set the static portion of our display up
// This does not change so there is no reason to display it over and over
// ****************************************************
void scrnsetup()
{
  lcd.setCursor(0,0);
  lcd.print("R:");
  lcd.setCursor(7,0);
  lcd.print("B:");
  lcd.setCursor(0,1);
  lcd.print("G:");
  lcd.setCursor(7,1);
  lcd.print("N:");
}


// ****************************************************
// Display our color values to the lcd display
// ****************************************************
void displaysensor()
{
  lcd.setCursor(3,0);
  lcd.print(red);
  lcd.setCursor ( 10,0);
  lcd.print(blue);
  lcd.setCursor(3,1);
  lcd.print(green);
  lcd.setCursor ( 10,1);
  lcd.print(nocolor);
}


// ****************************************************
//          Get the color values from our sensor
// 1 = red filter
// 2 = blue filter
// 3 = green filter
// 4 = no color filter
// ****************************************************
void getsensor() // Get the sensor values;
{
  red = getcolor (1,millis());
  blue = getcolor (2,millis());
  green = getcolor (3,millis());
  nocolor = getcolor (4,millis());
}


// ****************************************************
//         Our Main loop over and over again
// ****************************************************
void loop()
{
  displaysensor();
  getsensor();

}



Currently what I have.
8  Using Arduino / Programming Questions / Re: critique programming for tcs3200 / tcs3210 color sensor. on: September 12, 2012, 07:41:31 pm

I'd rather see all 4 sN pins set together.

I agree

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.)

I agree. thats why I asked. see if this is easier to read and understand. I may have over documented it this time?

It might be obvious to you how that sets scaling, but it isn't obvious to anyone else.

thats where I may have overdone the over documentation. In the data sheet and the sensor sheet there are
some inconsistancies I am still trying to get a handle on my self. bare with me a little here for the short term.


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.

I looked into volatile and it makes sense. I have implemented it. Thanks.

Code:
unsigned long  getcolor (int color,unsigned long colormillis)
Spacesbetweenargumentsarenice.

easy fix although not in this version.

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.

I would like for there to be no delay at all. I am still thinking this one over. I can increase the sensitivity of the sensor and reduce the time but in the end I would like for there to be no delay at all. That would mean handling the millis timing from the calling function rather than controling it from this function. If I increase the sensitivity it may effect millis as the program uses an interupt.

I am still thinking this over. I am probably thinking this over too much.


colormillis is a lousy name. Yes, the variable has something to do with time, but what, exactly? startTime would make more sense.

Better than naming it fred.

Is there any situation where more than one of these blocks will be executed? The else if statement should be deployed, here.

No, But that does not mean someone will not try. I will see if I can come up with a way to limit an operator error or programming error.

You have very similar actions in each block. A function, instead of cut and paste, would have been better.


Display some values, then get some values to display. Hmmm, something's wrong with this picture.
That is just what I was taught. Let main loop handle basic control and let your functions do the heavy lifting.
9  Using Arduino / Programming Questions / Re: critique programming for tcs3200 / tcs3210 color sensor. on: September 12, 2012, 07:24:38 am
Thanks paul.

I will clean up documenting a little more and work on the timer first. I will want it to check other sensor and perform other tasks while it is checking the sensor pulse values. As it is a full second elapses before the controller can do any other tasks.

I need to look up what the volitile description is for a variable. I have never used that before so its a new term to me.

Thanks again!
10  Using Arduino / Programming Questions / critique programming for tcs3200 / tcs3210 color sensor. on: September 11, 2012, 10:30:31 pm
I am doing this just an as exercise on learning for my own use.

Any help or wisdom is welcomed to make it better or easier to read or understand.

Code:
/*
TCS230 COLOR sensor from TAOS.
Written By Michael King
Copiertalk.com
Creative commons share alike.
 
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(53, 49, 41, 43, 45, 47);

int whatcolor = 0; // what color are we testing
unsigned long   currentmillis =  millis();
unsigned long   oldmillis = millis();
;

int s0 = 30; // Pins for our color sensor filters
int s1 = 31;
int s2 = 32;
int s3 = 33;
int oe = 35;
int ledpin = 13;

unsigned long red = 0;
unsigned long blue = 0;
unsigned long green = 0;
unsigned long nocolor = 0;
unsigned long sensorpulse = 0;


// ****************************************************
// Setup function
// This is executed once at the start of our program
// It sets up our pins for our sensor.
// ****************************************************
void setup()
{

  sensorpulse = 0; // I want to make sure this value starts at zero
  pinMode (s0, OUTPUT); // set up our sensor
  pinMode (s1, OUTPUT); // pins to control
  pinMode (s2, OUTPUT); // Color Filter.
  pinMode (oe,OUTPUT);
  pinMode (s3, OUTPUT);
  digitalWrite(oe,LOW);
  digitalWrite(s0,LOW); // Set scaling here.
  digitalWrite(s1,HIGH);
  digitalWrite(ledpin,HIGH);

  attachInterrupt(0, sensorisr, RISING);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  scrnsetup();

}

// ****************************************************
//         This is our interupt service routine.
// ****************************************************

void sensorisr ()
{
  sensorpulse ++; // Add 1 to our pulse count.
}

// ****************************************************
//          This function returns a value
// Depending on the color filter defined below.
// 1 = red filter
// 2 = blue filter
// 3 = green filter
// 4 = no color filter
// ****************************************************

unsigned long  getcolor (int color,unsigned long colormillis)
{
  unsigned long currentpulse;
  digitalWrite(ledpin,LOW); // turn leds on
  if (color == 1)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, LOW); // red
    digitalWrite ( s3, LOW);
    do 
    {
      currentpulse = sensorpulse;
    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }
  if (color == 2)
  {
    digitalWrite(oe,LOW); // Turn Sensor on
    digitalWrite ( s2, LOW); // BLue filter
    digitalWrite ( s3, HIGH);
    do 
    {
      currentpulse = sensorpulse;

    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }

  if (color == 3)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, HIGH); // greeen
    digitalWrite ( s3, HIGH);
    do 
    {
      currentpulse = sensorpulse;

    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }

  if (color == 4)
  {
    digitalWrite(oe,LOW); // turn sensor on
    digitalWrite ( s2, HIGH); // clear filter or no color
    digitalWrite ( s3, LOW);
    do 
    {
      currentpulse = sensorpulse;

    }
    while ((millis() - colormillis)  < 250); // check for 1/4 sencond;
  }
  sensorpulse=0; // reset our pulse count prior to leaving
  digitalWrite (oe,HIGH); // Turn sensor off
  // digitalWrite(ledpin,HIGH); // turn leds off if needed
  return currentpulse;
}
// ****************************************************
// set the static portion of our display up
// This does not change so there is no reason to display it over and over
// ****************************************************
// +++++++++++++++ set the lcd screen up ++++++++++++
void scrnsetup()
{
  lcd.setCursor(0,0);
  lcd.print("R:");
  lcd.setCursor(7,0);
  lcd.print("B:");
  lcd.setCursor(0,1);
  lcd.print("G:");
  lcd.setCursor(7,1);
  lcd.print("N:");
}


// ****************************************************
// Display our color values to the lcd display
// ****************************************************
// Position the cursor on the lcd and display the color values
void displaysensor()
{
  lcd.setCursor(3,0);
  lcd.print(red);
  lcd.setCursor ( 10,0);
  lcd.print(blue);
  lcd.setCursor(3,1);
  lcd.print(green);
  lcd.setCursor ( 10,1);
  lcd.print(nocolor);
}

// ****************************************************
//          Get the color values from our sensor
// 1 = red filter
// 2 = blue filter
// 3 = green filter
// 4 = no color filter
// ****************************************************
void getsensor() // Get the sensor values;
{
  red = getcolor (1,millis());
  blue = getcolor (2,millis());
  green = getcolor (3,millis());
  nocolor = getcolor (4,millis());
}


// ****************************************************
//         Our Main loop over and over again
// ****************************************************
void loop()
{
  displaysensor();
  getsensor();

}

I am working towards a device to test colors on a printed page but am just starting the project and want to get the sensor output so far. Let me know what you think.
11  Using Arduino / Sensors / Re: Finding sensors best suited to weather station project on: September 06, 2012, 11:58:40 pm
I have thought about building one I am not not commited to buying the components yet.

http://us.oregonscientific.com/cat-Weather-sub-Professional-Weather-Sensors-and-Extra-Displays-prod-Professional-Wind-Sensor-with-Poles-and-Complete-Mounting-Kit.html

Sparkfun had a rain guage / wind cup/direction sensor at one time but the last time I looked they were sold out.
12  Using Arduino / Sensors / Re: Temp sensor on: September 06, 2012, 11:49:37 pm
I used the hacktronix tutorial when I was setting up several sensors.

http://www.hacktronics.com/Tutorials/arduino-digital-temperature-sensor-tutorial.html
13  Using Arduino / Sensors / Re: Temp sensor on: September 06, 2012, 10:56:33 pm
there is a bunch of information out there for it.

http://lmgtfy.com/?q=ds18b20+arduino
14  Using Arduino / General Electronics / Re: Why use 2 decoupling capacitors? on: August 30, 2012, 09:15:33 pm
A question off the original if I can intrude into the thread.

When two or more caps are in parallel are the not added? such as

C = (10 μF) + (20 μF)
 
    = 30 (μF)
15  Using Arduino / Sensors / Re: Interfacing with FAX / Scanner Sensor on: August 23, 2012, 05:39:58 pm
depends on what fax or device it is pulled from.

Some were parallel back in the day. More modern units are serial.

I have not played with one with an arduino system. I have seen a couple of youtube vids on it in the past. You may check there and see if you get any hits.
Pages: [1] 2 3 ... 14