Simple.ino 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Simple tests for Tsl2561 class. No error checking is done.
  3. Copyright: Joachim Banzhaf, 2018
  4. This file is part of the Joba_Tsl2561 Library.
  5. Joba_Tsl2561 is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Joba_Tsl2561 is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Joba_Tsl2561. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <Tsl2561.h>
  17. // to mimic Serial.printf() of esp8266 core for other platforms
  18. char *format( const char *fmt, ... ) {
  19. static char buf[128];
  20. va_list arg;
  21. va_start(arg, fmt);
  22. vsnprintf(buf, sizeof(buf), fmt, arg);
  23. buf[sizeof(buf)-1] = '\0';
  24. va_end(arg);
  25. return buf;
  26. }
  27. Tsl2561 Tsl(Wire);
  28. void setup() {
  29. Serial.begin(115200);
  30. Wire.begin();
  31. Serial.println("\nStarting Tsl2561 simple loop");
  32. }
  33. void loop() {
  34. Tsl.begin();
  35. if( Tsl.available() ) {
  36. Tsl.on();
  37. Tsl.setSensitivity(true, Tsl2561::EXP_14);
  38. delay(16);
  39. uint8_t id;
  40. uint16_t full, ir;
  41. Tsl.id(id);
  42. Tsl.fullLuminosity(full);
  43. Tsl.irLuminosity(ir);
  44. Serial.print(format("Tsl2561 at 0x%02x(id=0x%02x) luminosity is %5u (full) and %5u (ir)\n", Tsl.address(), id, full, ir));
  45. Tsl.off();
  46. }
  47. else {
  48. Serial.println("No Tsl2561 found. Check wiring.");
  49. }
  50. delay(5000);
  51. }