No Description

tm1637.cxx 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "tm1637.h"
  25. #include <signal.h>
  26. #include <unistd.h>
  27. #include <sstream>
  28. #include <time.h>
  29. using namespace std;
  30. using namespace upm;
  31. bool run = true;
  32. void sig_handler(int signo)
  33. {
  34. if (signo == SIGINT)
  35. run = false;
  36. }
  37. int
  38. main(int argc, char** argv)
  39. {
  40. //! [Interesting]
  41. bool point = true;
  42. int timezone = -7; // Your UTC offset
  43. time_t rawtime;
  44. struct tm * gmt;
  45. char myTime[4];
  46. fprintf(stdout, "TM1637 Display Example\n");
  47. signal(SIGINT, sig_handler);
  48. TM1637 myDisplay = TM1637(0, 1); // TM1637 on pins 0 (clk) and 1 (dio)
  49. myDisplay.write(0x39, 0x09, 0x09); // Start a box using 7-segment encoding
  50. myDisplay.writeAt(3, ']'); // Finish box using writeAt function
  51. sleep(3); // Wait 3 seconds
  52. while(run)
  53. {
  54. time(&rawtime); // Update raw time
  55. gmt = gmtime(&rawtime); // Get current time
  56. // Format and store the time in 24 hour format
  57. sprintf(myTime, "%2d%02d", (gmt->tm_hour + timezone + 24) % 24, gmt->tm_min);
  58. myDisplay.write(myTime); // Write to display as string
  59. myDisplay.setColon(point ^= true); // Toggle the dots on the display
  60. sleep(1); // Only update once every second
  61. }
  62. //! [Interesting]
  63. return 0;
  64. }