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