element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino Flora with light sensor
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 19 replies
  • Answers 6 answers
  • Subscribers 393 subscribers
  • Views 1561 views
  • Users 0 members are here
  • light sensor
  • adafruit_flora
  • neopixels
  • arduino
Related

Arduino Flora with light sensor

Former Member
Former Member over 9 years ago

Hello all.  I am VERY new at Arduino coding, and I am trying to get my Flora and Neopixels to respond using the light sensor.  Something is wrong with my code, and no matter how I try to adjust it, I am still getting errors.  Any help would be appreciated....

And I apologize, but I don't know how to put code tags. 

 

The errors I am getting are the following:

 

(sketch file) light sensor.ino:162:5: error: use of undeclared identifier 'colorWipe'

  colorWipe(strip.Color(255,250,240));

  ^
(sketch file) light sensor.ino:167:5: error: use of undeclared identifier 'colorWipe'

  colorWipe(strip.Color(0,255,0));

  ^
(sketch file) light sensor.ino:172:5: error: use of undeclared identifier 'colorWipe'

  colorWipe(strip.Color(255,0,0));

 

My code so far:

 

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include <Adafruit_TSL2561_U.h>

#include <Adafruit_NeoPixel.h>

 

 

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, NEO_GRB + NEO_KHZ800);

 

 

 

 

 

 

/* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),

   which provides a common 'type' for sensor data and some helper functions.

  

   To use this driver you will also need to download the Adafruit_Sensor

   library and include it in your libraries folder.

   You should also assign a unique ID to this sensor for use with

   the Adafruit Sensor API so that you can identify this particular

   sensor in any data logs, etc.  To assign a unique ID, simply

   provide an appropriate value in the constructor below (12345

   is used by default in this example).

  

   Connections

   ===========

   Connect SCL to analog 5

   Connect SDA to analog 4

   Connect VDD to 3.3V DC

   Connect GROUND to common ground

   I2C Address

   ===========

   The address will be different depending on whether you leave

   the ADDR pin floating (addr 0x39), or tie it to ground or vcc.

   The default addess is 0x39, which assumes the ADDR pin is floating

   (not connected to anything).  If you set the ADDR pin high

   or low, use TSL2561_ADDR_HIGH (0x49) or TSL2561_ADDR_LOW

   (0x29) respectively.

   

   History

   =======

   2013/JAN/31  - First version (KTOWN)

*/

  

Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

 

 

/**************************************************************************/

/*

    Displays some basic information on this sensor from the unified

    sensor API sensor_t type (see Adafruit_Sensor for more information)

*/

/**************************************************************************/

void displaySensorDetails(void)

{

  sensor_t sensor;

  tsl.getSensor(&sensor);

  Serial.println("------------------------------------");

  Serial.print  ("Sensor:       "); Serial.println(sensor.name);

  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);

  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);

  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");

  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");

  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux"); 

  Serial.println("------------------------------------");

  Serial.println("");

  delay(500);

}

 

 

/**************************************************************************/

/*

    Configures the gain and integration time for the TSL2561

*/

/**************************************************************************/

void configureSensor(void)

{

  /* You can also manually set the gain or enable auto-gain support */

  // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */

  // tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */

  tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */

 

  /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */

  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */

  // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */

  // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

 

 

  /* Update these values depending on what you've set above! */ 

  Serial.println("------------------------------------");

  Serial.print  ("Gain:         "); Serial.println("Auto");

  Serial.print  ("Timing:       "); Serial.println("13 ms");

  Serial.println("------------------------------------");

}

 

 

 

 

 

 

/**************************************************************************/

/*

    Arduino setup function (automatically called at startup)

*/

/**************************************************************************/

void setup(void)

{

  Serial.begin(9600);

  Serial.println("Light Sensor Test"); Serial.println("");

 

  /* Initialise the sensor */

  if(!tsl.begin())

  {

    /* There was a problem detecting the ADXL345 ... check your connections */

    Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");

    while(1);

  }

 

  /* Display some basic information on this sensor */

  displaySensorDetails();

 

  /* Setup the sensor gain and integration time */

  configureSensor();

 

  /* We're ready to go! */

  Serial.println("");

  

    // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket

  #if defined (__AVR_ATtiny85__)

    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);

  #endif

  // End of trinket special code

 

 

 

 

  strip.begin();

  strip.show(); // Initialize all pixels to 'off'

}

 

 

 

 

/**************************************************************************/

/*

    Arduino loop function, called once 'setup' is complete (your own code

    should go here)

*/

/**************************************************************************/

void loop(void)

{

 

 

  /* Get a new sensor event */

  sensors_event_t event;

  tsl.getEvent(&event);

 

  /* Display the results (light is measured in lux) */

  if (event.light)

  {

    Serial.print(event.light); Serial.println(" lux");

  }

  else

  {

    /* If event.light = 0 lux the sensor is probably saturated

       and no reliable data could be generated! */

    Serial.println("Sensor overload");

  }

  delay(250);

 

 

 

 

 

  //>130 is (255, 250, 240)

if (event.light > 130)

{

    colorWipe(strip.Color(255,250,240));

}

// 129-50 is (0,255,0)

else if ((event.light > 50) && (event.light < 129))

{

    colorWipe(strip.Color(0,255,0));

}

// and <50 is (255, 0, 0)

else if (event.light < 50)

{

    colorWipe(strip.Color(255,0,0));

}

 

 

}

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 9 years ago +3
    Hey Jennifer, just for future reference, it would be easier if you just copy-pasted the link to your codebender project so that others can look at the code in an easier way, and even compile it to look…
  • Former Member
    Former Member over 9 years ago in reply to mcb1 +3
    yeah sure, i'm not saying it's the only way, or the "right" way, I'm just saying this helps a lot of back and forth questions of "which library version are you using", "do you have that installed", "ok…
  • Former Member
    Former Member over 9 years ago in reply to Former Member +2
    IT'S WORKING!!! I don't know exactly what I did, but thank you all soooo much! mcb1, you are awesome!!! I am completely thrilled, because now I know where I can change things on this code to be able to…
Parents
  • Former Member
    0 Former Member over 9 years ago

    Ugh.  Now I'm getting even more errors!  It says I have "no matching function for call to 'colorWipe'".  I thought I put in the function.....

     

    #include <Wire.h>

    #include <Adafruit_Sensor.h>

    #include <Adafruit_TSL2561_U.h>

    #include <Adafruit_NeoPixel.h>

     

     

    #define PIN 6

    Adafruit_NeoPixel strip = Adafruit_NeoPixel(4, PIN, NEO_GRB + NEO_KHZ800);

     

     

     

     

     

     

    /* This driver uses the Adafruit unified sensor library (Adafruit_Sensor),

       which provides a common 'type' for sensor data and some helper functions.

     

       To use this driver you will also need to download the Adafruit_Sensor

       library and include it in your libraries folder.

       You should also assign a unique ID to this sensor for use with

       the Adafruit Sensor API so that you can identify this particular

       sensor in any data logs, etc.  To assign a unique ID, simply

       provide an appropriate value in the constructor below (12345

       is used by default in this example).

     

       Connections

       ===========

       Connect SCL to analog 5

       Connect SDA to analog 4

       Connect VDD to 3.3V DC

       Connect GROUND to common ground

       I2C Address

       ===========

       The address will be different depending on whether you leave

       the ADDR pin floating (addr 0x39), or tie it to ground or vcc.

       The default addess is 0x39, which assumes the ADDR pin is floating

       (not connected to anything).  If you set the ADDR pin high

       or low, use TSL2561_ADDR_HIGH (0x49) or TSL2561_ADDR_LOW

       (0x29) respectively.

      

       History

       =======

       2013/JAN/31  - First version (KTOWN)

    */

     

    Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

     

     

    /**************************************************************************/

    /*

        Displays some basic information on this sensor from the unified

        sensor API sensor_t type (see Adafruit_Sensor for more information)

    */

    /**************************************************************************/

    void displaySensorDetails(void)

    {

      sensor_t sensor;

      tsl.getSensor(&sensor);

      Serial.println("------------------------------------");

      Serial.print  ("Sensor:       "); Serial.println(sensor.name);

      Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);

      Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);

      Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");

      Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");

      Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");

      Serial.println("------------------------------------");

      Serial.println("");

      delay(500);

    }

     

     

    /**************************************************************************/

    /*

        Configures the gain and integration time for the TSL2561

    */

    /**************************************************************************/

    void configureSensor(void)

    {

      /* You can also manually set the gain or enable auto-gain support */

      // tsl.setGain(TSL2561_GAIN_1X);      /* No gain ... use in bright light to avoid sensor saturation */

      // tsl.setGain(TSL2561_GAIN_16X);     /* 16x gain ... use in low light to boost sensitivity */

      tsl.enableAutoRange(true);            /* Auto-gain ... switches automatically between 1x and 16x */

     

      /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */

      tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);      /* fast but low resolution */

      // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS);  /* medium resolution and speed   */

      // tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS);  /* 16-bit data but slowest conversions */

     

     

      /* Update these values depending on what you've set above! */

      Serial.println("------------------------------------");

      Serial.print  ("Gain:         "); Serial.println("Auto");

      Serial.print  ("Timing:       "); Serial.println("13 ms");

      Serial.println("------------------------------------");

    }

     

     

     

     

     

     

    /**************************************************************************/

    /*

        Arduino setup function (automatically called at startup)

    */

    /**************************************************************************/

    void setup(void)

    {

      Serial.begin(9600);

      Serial.println("Light Sensor Test"); Serial.println("");

     

      /* Initialise the sensor */

      if(!tsl.begin())

      {

        /* There was a problem detecting the ADXL345 ... check your connections */

        Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!");

        while(1);

      }

     

      /* Display some basic information on this sensor */

      displaySensorDetails();

     

      /* Setup the sensor gain and integration time */

      configureSensor();

     

      /* We're ready to go! */

      Serial.println("");

     

        // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket

      #if defined (__AVR_ATtiny85__)

        if (F_CPU == 16000000) clock_prescale_set(clock_div_1);

      #endif

      // End of trinket special code

     

     

     

     

      strip.begin();

      strip.show(); // Initialize all pixels to 'off'

    }

     

     

     

     

    /**************************************************************************/

    /*

        Arduino loop function, called once 'setup' is complete (your own code

        should go here)

    */

    /**************************************************************************/

    void loop(void)

    {

     

     

      /* Get a new sensor event */

      sensors_event_t event;

      tsl.getEvent(&event);

     

      /* Display the results (light is measured in lux) */

      if (event.light)

      {

        Serial.print(event.light); Serial.println(" lux");

      }

      else

      {

        /* If event.light = 0 lux the sensor is probably saturated

           and no reliable data could be generated! */

        Serial.println("Sensor overload");

      }

      delay(250);

     

     

     

     

     

      //>130 is (255, 250, 240)

    if (event.light > 130)

    {

        colorWipe(strip.Color(255,250,240));

    }

    // 129-50 is (0,255,0)

    else if ((event.light > 50) && (event.light < 129))

    {

        colorWipe(strip.Color(0,255,0));

    }

    // and <50 is (255, 0, 0)

    else if (event.light < 50)

    {

        colorWipe(strip.Color(255,0,0));

    }

     

     

    }

     

     

    // Fill the dots one after the other with a color 

    void colorWipe(uint32_t c, uint8_t wait) { 

      for(uint16_t i=0; i<strip.numPixels(); i++) { 

          strip.setPixelColor(i, c); 

          strip.show(); 

          delay(wait); 

      } 

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 9 years ago in reply to Former Member

    jbarker822

    Jennifer.

    I think you're missing the wait value.

     

    The example shows this

      // Some example procedures showing how to display to the pixels:
      colorWipe(strip.Color(255, 0, 0), 50); // Red
      colorWipe(strip.Color(0, 255, 0), 50); // Green
      colorWipe(strip.Color(0, 0, 255), 50); // Blue

     

    You'll note that there is two parts ....  the RGB values and then the wait amount.  , 50

     

    void colorWipe(uint32_t c, uint8_t wait) shows it needs two numbers

     

     

    Your code is missing the important part. ... the wait value

    if (event.light > 130)

    {
        colorWipe(strip.Color(255,250,240));
    }

     

     

     

    Also when posting code please paste it in, then highlight it, and select the >> and then Syntax Highlighting and choose C++.

     

     

    I tend to save my files locally then copy them onto a memory stick to use somewhere else.

    I also tend to save with either date or date and time appended to ensure I can go backwards my changes aren't working as well as I want them to.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • mcb1
    0 mcb1 over 9 years ago in reply to Former Member

    jbarker822

    Jennifer.

    I think you're missing the wait value.

     

    The example shows this

      // Some example procedures showing how to display to the pixels:
      colorWipe(strip.Color(255, 0, 0), 50); // Red
      colorWipe(strip.Color(0, 255, 0), 50); // Green
      colorWipe(strip.Color(0, 0, 255), 50); // Blue

     

    You'll note that there is two parts ....  the RGB values and then the wait amount.  , 50

     

    void colorWipe(uint32_t c, uint8_t wait) shows it needs two numbers

     

     

    Your code is missing the important part. ... the wait value

    if (event.light > 130)

    {
        colorWipe(strip.Color(255,250,240));
    }

     

     

     

    Also when posting code please paste it in, then highlight it, and select the >> and then Syntax Highlighting and choose C++.

     

     

    I tend to save my files locally then copy them onto a memory stick to use somewhere else.

    I also tend to save with either date or date and time appended to ensure I can go backwards my changes aren't working as well as I want them to.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube