ArduboyTest.ino 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. Arduboy.ino
  3. Arduboy Test Example with U8x8
  4. Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
  5. Copyright (c) 2016, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #include <Arduino.h>
  29. #include <Arduboy.h>
  30. #include <U8x8lib.h>
  31. #ifdef U8X8_HAVE_HW_SPI
  32. #include <SPI.h>
  33. #endif
  34. // Arduboy 10 (Production, Kickstarter Edition)
  35. U8X8_SSD1306_128X64_NONAME_4W_HW_SPI u8x8(/* cs=*/ 12, /* dc=*/ 4, /* reset=*/ 6);
  36. ArduboyCore arduboyCore;
  37. ArduboyAudio arduboyAudio;
  38. ArduboyTunes arduboyTunes;
  39. void setup(void)
  40. {
  41. //u8x8.begin(/*Select=*/ A0, /*Right/Next=*/ 5, /*Left/Prev=*/ 9, /*Up=*/ 8, /*Down=*/ 10, /*Home/Cancel=*/ A1); // Arduboy DevKit
  42. u8x8.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8); // Arduboy 10 (Production)
  43. arduboyTunes.initChannel(PIN_SPEAKER_1);
  44. arduboyTunes.initChannel(PIN_SPEAKER_2);
  45. arduboyAudio.begin();
  46. }
  47. void msg(const char *txt)
  48. {
  49. u8x8.clear();
  50. u8x8.print(txt);
  51. }
  52. void loop(void)
  53. {
  54. static uint8_t c = 1;
  55. static uint8_t b = 0;
  56. u8x8.setFont(u8x8_font_chroma48medium8_r);
  57. c = u8x8.userInterfaceSelectionList("Arduboy Test\n", c, "LED Test\nButton Test\nSpeaker Test");
  58. if ( c == 1 )
  59. {
  60. msg("LED Test");
  61. arduboyCore.setRGBled(255, 0, 0);
  62. delay(500);
  63. arduboyCore.setRGBled(0, 255, 0); // green is not there ???
  64. delay(500);
  65. arduboyCore.setRGBled(0, 0, 255);
  66. delay(500);
  67. arduboyCore.setRGBled(0, 0, 0);
  68. }
  69. else if ( c == 2 )
  70. {
  71. u8x8.clear();
  72. for(;;)
  73. {
  74. u8x8.drawUTF8(0, 0, "Button Test");
  75. b = arduboyCore.buttonsState();
  76. u8x8.noInverse();
  77. if ( b & A_BUTTON )
  78. u8x8.inverse();
  79. u8x8.drawUTF8(0, 1, "A Button");
  80. u8x8.noInverse();
  81. if ( b & B_BUTTON )
  82. u8x8.inverse();
  83. u8x8.drawUTF8(0, 2, "B Button");
  84. u8x8.noInverse();
  85. if ( b & UP_BUTTON )
  86. u8x8.inverse();
  87. u8x8.drawUTF8(0, 3, "UP Button");
  88. u8x8.noInverse();
  89. if ( b & DOWN_BUTTON )
  90. u8x8.inverse();
  91. u8x8.drawUTF8(0, 4, "DOWN Button");
  92. u8x8.noInverse();
  93. if ( b & LEFT_BUTTON )
  94. u8x8.inverse();
  95. u8x8.drawUTF8(0, 5, "LEFT Button");
  96. u8x8.noInverse();
  97. if ( b & RIGHT_BUTTON )
  98. u8x8.inverse();
  99. u8x8.drawUTF8(0, 6, "RIGHT Button");
  100. u8x8.noInverse();
  101. u8x8.drawUTF8(0, 7, "Quit: A&B Button");
  102. if ( (b & A_BUTTON) && (b & B_BUTTON) )
  103. break;
  104. }
  105. }
  106. else if ( c == 3 )
  107. {
  108. u8x8.clear();
  109. u8x8.drawUTF8(0, 0, "Speaker Test");
  110. arduboyTunes.tone(1000, 1000);
  111. delay(1000);
  112. arduboyTunes.tone(2000, 1000);
  113. delay(1000);
  114. }
  115. }