-
-
Save Pharap/afd7016eabd2e0fc5bab00b8eb43b450 to your computer and use it in GitHub Desktop.
Alt_f demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduboy2.h> | |
#include <ab_logo.c> | |
// FlashStringHelper.h needs to be in the same directory as your .ino file | |
#include "FlashStringHelper.h" | |
Arduboy2 arduboy; | |
constexpr uint8_t AB_LOGO_WIDTH = 88; | |
constexpr uint8_t AB_LOGO_HEIGHT = 16; | |
//integers | |
int playerHP = 20; | |
int playerXP = 0; | |
const char sword0[] PROGMEM = "Rusty Shortsword"; | |
const char sword1[] PROGMEM = "Iron Shortsword"; | |
const char sword2[] PROGMEM = "Iron Longsword"; | |
const char sword3[] PROGMEM = "Elvish Shortsword"; | |
const char sword4[] PROGMEM = "Elvish Longsword"; | |
const char sword5[] PROGMEM = "Enchanted Shortsword"; | |
const char sword6[] PROGMEM = "Emerald Greatsword"; | |
const char * const swords[7] PROGMEM | |
{ | |
sword0, | |
sword1, | |
sword2, | |
sword3, | |
sword4, | |
sword5, | |
sword6, | |
}; | |
const char armour0[] PROGMEM = "Common Garb"; | |
const char armour1[] PROGMEM = "Leather Tunic"; | |
const char armour2[] PROGMEM = "Chainmail"; | |
const char armour3[] PROGMEM = "Iron Chestplate"; | |
const char armour4[] PROGMEM = "Elvish Chestplate"; | |
const char armour5[] PROGMEM = "Dwarvish Chestplate"; | |
const char armour6[] PROGMEM = "Enchanted Chestplate"; | |
const char armour7[] PROGMEM = "Dragon Scales"; | |
const char * const armour[8] PROGMEM | |
{ | |
armour0, | |
armour1, | |
armour2, | |
armour3, | |
armour4, | |
armour5, | |
armour6, | |
armour7, | |
}; | |
void setup() | |
{ | |
arduboy.begin(); | |
} | |
void loop() | |
{ | |
if (!arduboy.nextFrame()) | |
return; | |
arduboy.clear(); | |
if(arduboy.pressed(B_BUTTON)) | |
{ | |
arduboy.print(F("XP:")); | |
arduboy.println(playerXP); | |
arduboy.print(F("HP:")); | |
arduboy.println(playerHP); | |
arduboy.print(F("Sword:")); | |
arduboy.println(readFlashStringPointer(&swords[0])); | |
arduboy.print(F("Armour:")); | |
arduboy.println(readFlashStringPointer(&armour[0])); | |
} | |
arduboy.display(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
// | |
// Copyright (C) 2019 Pharap (@Pharap) | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, | |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
// See the License for the specific language governing permissions and | |
// limitations under the License. | |
// | |
// Include __FlashStringHelper | |
#include <WString.h> | |
// | |
// FlashStringHelper | |
// | |
using FlashStringHelper = const __FlashStringHelper *; | |
// | |
// asFlashStringHelper | |
// | |
inline FlashStringHelper asFlashStringHelper(const char * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(static_cast<const void *>(flashString)); | |
} | |
inline FlashStringHelper asFlashStringHelper(const unsigned char * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(static_cast<const void *>(flashString)); | |
} | |
inline FlashStringHelper asFlashStringHelper(const signed char * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(static_cast<const void *>(flashString)); | |
} | |
// Include pgm_read_ptr | |
#include <avr/pgmspace.h> | |
// | |
// readFlashString | |
// | |
inline FlashStringHelper readFlashStringPointer(const char * const * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(pgm_read_ptr(flashString)); | |
} | |
inline FlashStringHelper readFlashStringPointer(const unsigned char * const * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(pgm_read_ptr(flashString)); | |
} | |
inline FlashStringHelper readFlashStringPointer(const signed char * const * flashString) noexcept | |
{ | |
return static_cast<FlashStringHelper>(pgm_read_ptr(flashString)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment